From: Arthur Flatau

Subject: Random function.

Date: 2003-5-2 10:27


> The random function uses a *random-state* data structure. When the random > function is called it performs a side effect on this data structure.
> I have a function that uses this random function. This function is called > many times, and each time it uses the random function to generate a set > of random numbers. I want each set of random numbers to be independent of > the previously generated set of random numbers. I do not make use of the > *random-state* data structure in my code.
> My questions are: > Are my set of random numbers independent of the previously > generated set of random numbers? > Does the *random-state* data structure need to be initialized or > something like that? > What actually is the purpose and effect of the *random-state* data > structure on the LISP environment?
Praveen, When Allegro CL starts up, *random-state* has an initial value that was generated when the image was built. This means that the sequence of random numbers generated will be the same. This is actually a desirable property as there are often cases when you want to save the seed (i.e. the random state) so you can generate those number again (this is useful for debugging). To get a new random state or seed do: (setq *random-state* (make-random-state t)) Of course, the numbers generated by calls to random are not really random, they are pseudo-random and are generated based on a seed, which is changed so a new pseudo-random number is generated the next time. This is typical of most programming languages. Unfortunately, make-random-state returns a new random state that is entirely based on the time of day in seconds (I would have to look up which CL functions returns that). This means that it is possible when running on multiple machines to generate the same sequence, if your calls to make-random-state on the different machines are close enough temporally. There is no way to provide some other number to initialize the random state. Art -- Arthur Flatau Texas Microprocessor Division <amd.com at Arthur.Flatau> Advanced Micro Devices Senior Member of Technical Staff 5900 East Ben White Boulevard M/S 625 Austin TX 78741