rng - A random number generator CLI tool.
Contains a number of (pseudo) random number generator algorithms. Given one of these it prints an infinite stream of bytes generated from that algorithm to stdout.
In unix terms it can basically be viewed as the equivalent of cat /dev/urandom
but with a
selection of different (mostly user-space) PRNG algorithms to choose from.
This tool is basically a CLI frontend for the awesome rand
crate.
How to use
This tool is very simple and have very few arguments:
rng [--seed <seed>] [<algorithm>]
If no arguments are given it uses the default algorithm and seeds it from the operating system. You might want to change the algorithm in order to fit your needs. Maybe you need a faster algorithm that is not cryptographically secure for example.
The --seed <seed>
argument initializes the random number algorithm with the given <seed>
instead
of obtaining some entropy from the operating system. You don't want to use this for any
cryptographical purposes. Giving a seed can be useful when you need determinism and must be able
to produce identical data in multiple runs.
Example
We try using the PCG algoritm a few times. Here we see that without a seed it produces different output each time, and with a seed it produces the same data as long as the seed is the same.
| |
| |
| |
| |
| |
Why?
This tool was invented because I needed to benchmark IO (both filesystem and network) on Linux.
Reading from /dev/urandom
was too slow, the machine spent too much time computing the actual data
and too little time performing the IO I wanted to test. On the other hand, getting data from
/dev/zero
is fast! But any compression (common in both network protocols and filesystems) will be
able to optimize this stream down to almost nothing. And again, the actual IO is not being properly
benchmarked.
So what I needed was a very fast stream of incompressible data. The rand
crate provides a unified
interface to a number of different random number algorithms. Some of them suiting my use case.