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.cc
- One way to use an LCG to permute a string.
- minStdRandGenC.c
minStdRandGenF.f
minStdRandGenPL.pl minStdRandGenPY.py minStdRandGenRB.rb minStdRandGenCL.clisp - Implementation of the minimal standard random number generator in various languages requiring no more than 32-bit arithmetic. A direct implementation of the LCG algorithm for the minimal standard leads to overflow with 32-bit arithmetic. Note the careful sequencing of operations to avoid overflow.
- smplMinStdRandGenRB.rb smplMinStdRandGenCL.clisp
- Simplistic implementation of the minimal standard random number generator using two languages supporting arbitrary precession arithmetic. Similar approaches are possible with tools like the GMP library in C (see: gmpLCG.c)
- gmpLCG.c
- General LCG implementation with GMP.
- randFileEx.c randFileC.c randFileC.h
- One way to use a file full of random bytes as a random number generator. High quality files are available on the web and on CD-ROM. One can also obtain them from true random hardware sources, or cryptographic packages.
- 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. Also note the Fortran 90 module specifying interfaces for some functions in 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.