On 2017-09-23,
jshr...@gmail.com <
jshr...@gmail.com> wrote:
> I'm using ccl and hunchentoot. I discovered that each thread needs to
> have a new random state, otherwise you get the same random sequence
> each time through, so now the first thing I do in my thread code is
> (setf *random-state* (make-random-state t)), but this seems wrong.
> First off, it's setting the global *random-state* every time a thread
> starts.
The way out of that is of course:
(let ((*random-state* (make-random-state t)))
... rest of thread code...)
> Also, there should be a way to do this with some sort of
> :before method on the hunchentoot thread spinner, so that I don't have
> to do this at the head of every server. As always, your guidance
> appreciated!
Not familiar with that thread spinner, but as a general note, I think
this would have to be an :around method, so you could do, in its body,
something like:
(let ((*random-state* (make-random-state t)))
(call-next-method)) ;; the next method has the thread body.
A :before method will return before the next method is dispatched,
which will unravel any bindings it set up.