Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.lisp > #60795
| From | steve g <sgonedes1977@gmail.com> |
|---|---|
| Newsgroups | comp.lang.lisp |
| Subject | Re: Make a random-state from a non-random source |
| References | <jwvmryfku8t.fsf-monnier+comp.lang.lisp@gnu.org> |
| Date | 2026-06-01 15:10 -0400 |
| Message-ID | <87h5nmule3.fsf@gmail.com> (permalink) |
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 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
(defun gensym (&optional (thing "G"))
"Creates a new uninterned symbol whose name is a prefix string (defaults
to \"G\"), followed by a decimal number. Thing, when supplied, will
alter the prefix if it is a string, or be used for the decimal number
if it is a number, of this symbol. The default value of the number is
the current value of *gensym-counter* which is incremented each time
it is used."
(multiple-value-bind (prefix int)
(if (integerp thing)
(values "G" thing)
(values thing (let ((old *gensym-counter*))
(setq *gensym-counter* (1+ old))
old)))
(make-symbol (%symbol-nameify prefix int))))
this is from sbcl symbol.lisp.
a very poor way of doing this would look like this...
(let ((*gensym-counter* 25))
(gensym "CNT"))
I do not recommend doing this with gentemp, at least with sbcl.
Hencefold the worst way to make a random symol..!
Back to comp.lang.lisp | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Make a random-state from a non-random source Stefan Monnier <monnier@iro.umontreal.ca> - 2026-05-04 12:46 -0400
Re: Make a random-state from a non-random source Alan Bawden <alan@csail.mit.edu> - 2026-05-05 00:45 -0400
Re: Make a random-state from a non-random source Stefan Monnier <monnier@iro.umontreal.ca> - 2026-05-05 16:03 -0400
Re: Make a random-state from a non-random source Kaz Kylheku <046-301-5902@kylheku.com> - 2026-06-04 23:45 +0000
Re: Make a random-state from a non-random source tfb <no_email@invalid.invalid> - 2026-05-09 18:20 +0000
Re: Make a random-state from a non-random source Stefan Monnier <monnier@iro.umontreal.ca> - 2026-05-11 11:23 -0400
Re: Make a random-state from a non-random source steve g <sgonedes1977@gmail.com> - 2026-06-01 15:10 -0400
Re: Make a random-state from a non-random source Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-01 23:58 +0000
csiph-web