[Ecls-list] making RANDOM's results repeat?

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun May 17 12:27:57 UTC 2009


On Wed, May 6, 2009 at 10:23 PM, Dorai Sitaram <ds26gte at yahoo.com> wrote:
> ECL's RANDOM by default does not seem to produce repeatable
> results across sessions.  While this can be a feature, is there an
> easy way to get repeatability, which seems to be de facto
> standard behavior in other Lisps?

Sorry for the late answer. What you want is to save the random state.
Take the following two files

foo.lisp
(with-open-file (s "random-state.lisp" :direction :output :if-exists :supersede)
  (write `(setf *random-state* ,(make-random-state)) :readably t :stream s))
(quit)

faa.lisp
(load "random-state.lisp")
(princ (random 1.0d0))(terpri)
(quit)

$ ecl -norc -load 'foo.lisp'
...
$ ecl -norc -load 'faa.lisp'
;;; Loading "/Users/jjgarcia/src/ecl-test/faa.lisp"
;;; Loading "/Users/jjgarcia/src/ecl-test/random-state.lisp"

0.07783766789361835d0
$ ecl -norc -load 'faa.lisp'
;;; Loading "/Users/jjgarcia/src/ecl-test/faa.lisp"
;;; Loading "/Users/jjgarcia/src/ecl-test/random-state.lisp"

0.07783766789361835d0



-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28009 (Spain)
http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list