Random number generation, and random seeds.



How many random numbers do you need?  If it is a modest number, like
10,000,   why not fill an array with 10,000 "random" numbers, and to
get the next one, just increment the counter.  When you want to
run the same numbers again, just set the counter back to 1 (or 0).

I did something like this when I wanted a really fast RN generator
but I was not terribly concerned about randomness..  I think I
didn't use an array, but I used a circularly linked list.  Getting
the next pseudo-random number from the circular list L consisted of
the lisp expression  (pop L)
which expands to something like

(prog1 (car L)(setq L (cdr L))

  the Maxima in Allegro CL presumably will allow setting the seed.


Raymond Toy wrote:

>>>>>>"Stavros" == Stavros Macrakis <macrakis@gmail.com> writes:
> 
> 
>     >> I would like to generate pseudo-random numbers in maxima, from a definite seed.
>     Stavros> The Maxima Random command uses the Common Lisp random function, which
>     Stavros> has no way to set the seed to a definite value.  It does provide for a
>     Stavros> random state object which is printable and readable (thus allowing
>     Stavros> reproducible random sequences), but GCL is not compliant to this
>     Stavros> requirement: its random state objects are not readable.  So in
>     Stavros> Maxima/GCL, though it is possible to restart a random sequence in the
>     Stavros> same place within a run, it isn't possible to restart it in the same
>     Stavros> place in two distinct runs.
> 
> It would, however, be relatively easy to provide a new random command
> that can be seeded.
> 
> CMUCL has a mostly portable implementation of MT-19937.  The cl-bench
> benchmarks has portable mrg32k3a generator.  Both of these are
> regarded as pretty good generators.
> 
> MT-19937 requires some 600 32-bit words of state.  mrg32k3a requires 6
> double-floats of state.
> 
> Ray
> 
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima