Jump to my Home Page Send me a message Check out stuff on GitHub Check out my photography on Instagram Check out my profile on LinkedIn Check me out on Facebook

Random Number Example Programs

Good random number generation is easy with all of the tools available to the modern programmer. Here you will find a number of examples showing how to get random numbers from various sources. The makefile is here.

Random Topics. :)

One way to use an LCG to permute a string.
minStdRandGenC.c minStdRandGenF.f
minStdRandGenPL.pl minStdRandGenPY.py minStdRandGenRB.rb minStdRandGenCL.clisp
32-bit overflow avoiding implementation of the minimal standard random number generator.
smplMinStdRandGenRB.rb smplMinStdRandGenCL.clisp
Arbitrary precision arithmetic implementation of the minimal standard random number generator via native language support.
Arbitrary precision arithmetic implementation of the minimal standard random number generator via GMP
randFileEx.c randFileC.c randFileC.h
How use files full of random bytes as a random number generator. High quality files are available on the web and on CD-ROM.
Approximate the value of Pi with random numbers (uses the GMP)

Low Quality Generators (UNIX based)

How to make use of the BSD random(), srandom(), and srandomdev() functions.
How to make use of the rand48 group of functions found on many UNIX platforms

Other Low Quality Generators

Simple use of the random functions in the GMP.

Low Quality Standard Language Generators

How to use RANDOM_SEED() and RANDOM_NUMBER()in standard Fortran 90
How use the srand() and rand() functions specified in ISO C
How to make use of the Common Lisp random number generator.

RANLIB (A Trusted Simulation Quality Generator)

ranlibExF.f90 ranlibM.f90
Relatively complete example illustrating the Fortran version of RANLIB and a Fortran 90 module specifying some interfaces to RANLIB.
ranlibExFC.c ranlibF.h ranlibF.c
C version of ranlibExF.f90 using simple C wrappers for the Fortran library.
Short example showing how to use the C version of RANLIB.

Simulation Quality Generators

Simple example illustrating how to use the GSL random number generators.
Minimal example of the boost random number generator. The make file is here.
Example showing how to use PRNG

Cryptographic Generators

Trivial use of OpenSSL to generate random numbers.
© 2009 Mitch Richling