Monday 26 November 2018

How do you specify a range of random numbers?

The Common Lisp function RANDOM takes two arguments: a limit and a random state. The first argument tells to the function that the generated random number could be one in the range of 0 <= n < limit, for example:

CL-USER> (random 1000)
860

or:

CL-USER> (random 1.0)
0.2709539

from these examples we clearly understand that limit could be an integer or float number. The second parameter passed to RANDOM is the random state, according to hyperspec http://clhs.lisp.se/Body/t_rnd_st.htm#random-state) is an object which holds informations used by the random number generator inside the computer which are different from implementation to implementation.