tr -dc 0-9 < /dev/urandom | fold -w 3 | awk '$0>=100 && $0<=200' What this line does:
- /dev/urandom (Linux) is proven to be a CSPRNG, that is not a question
- the "
tr -dc 0-9 < /dev/urandom | fold -w 3" outputs 3 digit long numbers from /dev/urandom, ex.: 630, 418, 037, 992, 186, etc.
The question: we need numbers only in an interval, but we need those numbers to be cryptographically secure pseudo random numbers. We use the following: awk '$0>=100 && $0<=200' to only allow numbers (x) inside a given interval (100 <= x <= 200). Are these numbers (limited due to the interval) still considered as cryptographically secure pseudo random numbers?
/dev/urandomoutputs random bytes, and you then usetrto delete (tr -d, delete) all characters in this output, except (-c, use complementary set) for the digits 0 through 9. So on average, assuming that your system uses UTF-8 (where those digits are represented by a single byte each), you are throwing away all but 10/256 of the bytes read, resulting in actually further processing only 3.9% of /dev/urandom's output. I don't know if this changes its security properties in any way, but suspect that it makes predicting the PRNG output harder. $\endgroup$/dev/urandomoutputs bytes (which can be treated as integer values in the range $[0,255]$: 0 through 255 inclusive). Call one such byte value when treated as an integer $c$. Now compute the remainder of the integer division $\frac{c}{101}$ (also known as $c$ modulo 101) -- this transforms the value to one in the range $[0,100]$, because the remainder of an integer division will always be 0 through one less than the divisor. Add 100 to the remainder of the division to bring the total ($100 + [0,100]$) to your desired range $[100,200]$. Clear enough? You can use >1 byte at a time. $\endgroup$