• Make a random-state from a non-random source

    From Stefan Monnier@monnier@iro.umontreal.ca to comp.lang.lisp on Mon May 4 12:46:57 2026
    From Newsgroup: comp.lang.lisp

    Reading the CLHS about `make-random-state` I can't see how to create
    a "deterministic" random state.

    I want it to be deterministic in the sense that if I re-run my program (including after changing it a bit), I'll get the exact same sequence of
    random numbers.
    It's OK if the sequence is different when run on a different Lisp implementation, OTOH.

    I guess I could print a random state into a file and then read it back in,
    but that depends on internals, so it's doubly messy.


    === Stefan
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Alan Bawden@alan@csail.mit.edu to comp.lang.lisp on Tue May 5 00:45:13 2026
    From Newsgroup: comp.lang.lisp

    Stefan Monnier <monnier@iro.umontreal.ca> writes:

    Reading the CLHS about `make-random-state` I can't see how to create
    a "deterministic" random state.

    ...

    I guess I could print a random state into a file and then read it back in, but that depends on internals, so it's doubly messy.

    That what you are intended to do. That's why implementations are
    required to provide a read syntax for objects of type RANDOM-STATE.
    (See section 22.1.3.10 "Printing Random States" in the hyperspec.)

    Yes, it could be more convenient, but it isn't.

    - Alan
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From Stefan Monnier@monnier@iro.umontreal.ca to comp.lang.lisp on Tue May 5 16:03:12 2026
    From Newsgroup: comp.lang.lisp

    That what you are intended to do. That's why implementations are
    required to provide a read syntax for objects of type RANDOM-STATE.
    (See section 22.1.3.10 "Printing Random States" in the hyperspec.)
    Yes, it could be more convenient, but it isn't.

    Is there some non-standard approach provided by some Common Lisp implementations that is more convenient?

    E.g. in ELisp, `random` can be passed a string as "random seed".


    === Stefan
    --- Synchronet 3.21f-Linux NewsLink 1.2
  • From tfb@no_email@invalid.invalid to comp.lang.lisp on Sat May 9 18:20:49 2026
    From Newsgroup: comp.lang.lisp

    Stefan Monnier <monnier@iro.umontreal.ca> wrote:

    I guess I could print a random state into a file and then read it back in, but that depends on internals, so it's doubly messy.


    It only depends on internals in the sense that you don't know what the
    details of a random-state object are. You *do* know that printing and then reading one results in an equivalent object.

    So all you need to do is (inside with-standard-io-syntax if need be) is
    print one. Then you can simply say

    (defvar *my-random-state*
    #+<impl>
    <paste thing you just printed>
    ... versions for any other implementations ...
    #-(or <impl> ...)
    (error "add a case"))
    --
    www.tfeb.org/computer/
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Stefan Monnier@monnier@iro.umontreal.ca to comp.lang.lisp on Mon May 11 11:23:31 2026
    From Newsgroup: comp.lang.lisp

    tfb [2026-05-09 18:20:49] wrote:
    Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    I guess I could print a random state into a file and then read it back in, >> but that depends on internals, so it's doubly messy.
    It only depends on internals in the sense that you don't know what the details of a random-state object are. You *do* know that printing and then reading one results in an equivalent object.

    So all you need to do is (inside with-standard-io-syntax if need be) is
    print one. Then you can simply say

    (defvar *my-random-state*
    #+<impl>
    <paste thing you just printed>
    ... versions for any other implementations ...
    #-(or <impl> ...)
    (error "add a case"))

    Hmm... interesting. So that a case where the availability of
    reader-level conditionals has influenced the design of a "primitive".
    Thanks,


    === Stefan
    --- Synchronet 3.22a-Linux NewsLink 1.2