$ curl -o example002_libc_random.c https://priverify.com/sd/demo/libc_random/example002_libc_random.c $ curl -o compare_outputs.pl https://priverify.com/sd/demo/libc_random/compare_outputs.pl $ chmod +x compare_outputs.pl $ gcc example002_libc_random.c -o example002_libc_random $ ./example002_libc_random 1 5 Compare against https://priverify.com/demo/rng_simulate/00000001000000010000000300000005/fmt2 $ cat output_example001_libc_random.txt 1804289383 846930886 1681692777 1714636915 1957747793 $ curl https://priverify.com/demo/rng_simulate/00000001000000010000000300000005/fmt2 1804289383 846930886 1681692777 1714636915 1957747793
In the above example (as the very short example program shows), you are calling the srandom() function to seed the value of the first command line argument to the program (1) and then it outputs the number of calls to random() (count specified by the second command line argument to the program) to a file named output_example001_libc_random.txt and gives you the URL to an RNG Simulator that we have developed - which outputs the same results as on your local Linux or OSX system.
**This is a very simple, but very surprising to most programmers, example of how it is trivial to effectively assume that calls to random() are NOT at all random and are completely reproduceably given a particular seed via srandom(). If srandom() is NOT called, or if it is called with values of 0 or 1, then the results of the output sequence are always the same sequence. If srandom() is called with any other value, then given that particular value, the output sequence of random() are always the same.
TODO: - outline the above slight difference between Linux and Apple, which although NOT relevant in the outcome of calls to random() when a single call is made to srandom() within a particular program's run, where in Apple OSX multiple calls to srandom() will be ignored by their libc/gcc environment -- thus the example programs in this series communicate the environment via the URL to the PriVerify RNG Simulate application.