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. :)

lcgPermPowTwo.cpp
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.
gmpLCG.c
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.
randPi.c
Approximate the value of Pi with random numbers (uses the GMP)

Low Quality Generators (UNIX based)

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

Other Low Quality Generators

gmpRandEx.c
Simple use of the random functions in the GMP.

Low Quality Standard Language Generators

f90Rand.f90
How to use RANDOM_SEED() and RANDOM_NUMBER()in standard Fortran 90
isocRandEx.c
How use the srand() and rand() functions specified in ISO C
clispRandEx.lisp
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.
ranlibExC.c
Short example showing how to use the C version of RANLIB.

Simulation Quality Generators

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

Cryptographic Generators

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