Thirty Two Bit Random Integers
Fast generator for pseudorandom 32bit integers
This is the "fast" linear congruential pseudorandom number
generator `ranqd1' from chapter 7 of Numerical Recipes. Note that
because Scheme systems generally offer native support for "big"
integers, one has to use `modulo' in the Scheme code to emulate the
behavior of 32bit Fortran and C systems.
See http://libwww.lanl.gov/numerical/bookfpdf/f71.pdf for details.
Note that this is a very old, and very very poor, pseudorandom number generator. You should not use the code described on this page for any serious purpose, such as a MonteCarlo simulation. Under Linux /dev/urandom (see RandomIntegerFromDevURandom for details) is an excellent source for good random numbers. You might also want to check the random() library function of the standard C library.
This code is also available from http://www.scsh.net/contrib/emilio.lopes/scheme.html.
ECL
The Code
(define (genranqd1 seed)
(let ((random seed)
(2**32 #x100000000))
(lambda ()
(set! random (modulo (+ (* random 1664525) 1013904223) 2**32))
random)))
Testing
You can use the following code to test `ranqd1' with your Scheme
implementation:
(let ((random (genranqd1 0))
(expectedresults '(#x3c6ef35f
#x47502932
#xd1ccf6e9
#xaaf95334
#x6252e503
#x9f2ec686
#x57fe6c2d
#xa3d95fa8
#x81fdbee7
#x94f0af1a
#xcbf633b1)))
(foreach (lambda (expected)
(let ((rnd (random)))
(if (not (= rnd expected))
(error (format #f "FAILED: expected ~a, got ~a" expected rnd)))))
expectedresults))
More on Random Numbers
SRFI27 (http://srfi.schemers.org/srfi27/) by Sebastian Egner
specifies an interface to sources of random bits. There is also
a workshop on a portable random number generator in
Scheme (http://www.math.grin.edu/~stone/events/schemeworkshop/random.html)
by John David Stone.
ThirtyTwoBitRandomIntegers  raw wiki source 
code snippets archive
