Mitch Richling: Random Number Example Programs
| Author: | Mitch Richling |
| Updated: | 2023-11-15 |
Table of Contents
1. Introduction
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.
Get it all on github: https://github.com/richmit/ex-random/
2. 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
GMP)
3. 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
4. Other Low Quality Generators
gmpRandEx.c- Simple use of the random functions in the
GMP.
5. 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.
6. 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.f90using simple C wrappers for the Fortran library. ranlibExC.c- Short example showing how to use the C version of RANLIB.
7. Simulation Quality Generators
prngEx.c- Example showing how to use PRNG
boostRandEx.cpp- Example showing how to use boost. See the
makefile. gslRand.c- Example showing how to use GSL. See the
makefile.
8. Cryptographic Generators
opensslPRandEX.c- Trivial use of OpenSSL to generate random numbers.