This page presents two programs,
written in two different languages,
that do almost the same thing. One, lcgrng, is in Python. The other,
fast-pseudorandom, is written in C (using a gcc/clang extension, __int128).
Their command line options are actually a little different, but under
the hood they both use the same Linear Congruential Random Number
Generator algorithm.
Usage is like:
$ ./lcgrng --help
below cmd output started 2025 Sat Jul 19 09:09:01 PM PDT
Usage: ./lcgrng --bytes n --seed s
above cmd output done 2025 Sat Jul 19 09:09:01 PM PDT
dstromberg@tp-mini-c:~/src/home-svn/lcgrng/trunk x86_64-pc-linux-gnu 3933186
$ ./fast-pseudorandom --help
below cmd output started 2025 Sat Jul 19 09:09:08 PM PDT
Usage: ./fast-pseudorandom [--help] [-seed seed] [--bytes num_bytes]
--help Show this help message
--seed seed Set the RNG seed
--bytes num_bytes Number of bytes to output (must be a multiple of 256 Kilobytes: 262144)
This program just writes a seedable stream of pseudorandom characters pretty rapidly,
and with a pretty long period.
If you need good entropy, you want /dev/random or prngd or something instead.
It should have a full 64 bit period, and is relatively fast.
The programs just write a stream of pseudorandom characters pretty rapidly, and
with an optional seed value. The seed is mostly useful for reproducibility, EG
if you want to generate lots of random data that won't foul up your backups as much
(assuming a deduplicating backup program).
If you need good entropy, you want /dev/random or prngd or something instead.
They both should give a full 64 bit period for the bytes output when taken 16
bytes at a time.
On one system I checked, I saw the following performance results: