The Random Number Library (v.1.1 250616)
© W O Riha

1. Random Number Generators Designing a ‘good and
efficient’ random number generator (RNG) is
not an easy task! A lot has been written in the
literature (click here), and a large number of
techniques have been developed (see, for example,
List of Random Number
Generators).
We provide two
simple methods.
Method 1: (see http://en.wikipedia.org/wiki/Combined_Linear_Congruential_Generator)
Method 2: This method is due to D. Knuth (see http://en.wikipedia.org/wiki/Linear_congruential_generator)
It is simpler and
computationally cheaper, but perhaps less
‘random’. The function names all have
the suffix ‘Knuth’ – no examples
are quoted in the following description.
Note: If only a
few random numbers are required, either method
will be satisfactory. Where an application
depends on hundreds of thousands random numbers,
it might pay to make use of the LISP random
number generator which is considerably faster


2. Random Number Functions
random01 :
> number
random01Knuth : > number
Input: none
Output: a random number in the interval [0 1)
(random01)
0.42611619002179996 : number
(random01)
0.24454672298695493 : number
(random01)
0.7647986388801989 : number
rand :
number > number > number
randKnuth : number > number > number
Input: two numbers A and B (A < B)
Output: a random number in the interval [A B)
(rand 1
1)
0.5656633158593354 : number
(rand 1 1)
0.5141242093874876 : number
(rand 0 1000)
893.1472259189534 : number
randomint :
number > number > number
randomintKnuth : number > number > number
Input: two numbers A and B (A < B)
Output: a random integer in the interval [A B)
(randomint
1 11) \\ between 1 and 10 (inclusive)
4 : number
(randomint 1 11)
7 : number
random :
number > number > number
randomKnuth : number > number > number
Input: two numbers A and B (A < B)
Output: if both A and B are integers, a random integer in
the interval [A B) otherwise a random number in [A B).
Note: this function is ‘more expensive’!
(random
1 12)
9 : number
(random 1 12.001)
3.287118902233013 : number
