On Apr 2, 2009, at 9:37 PM, Eduardo Cavazos wrote:
Aziz,
Is there a way to seed the random number generator? I.e. for use
with the 'random' procedure?
Ed
You can define srandom as follows (and should probably submit a bug
report for its inclusion):
> (import (ikarus foreign))
> (define srandom ((make-c-callout 'void '(unsigned-long)) (dlsym
(dlopen) "srandom")))
> (srandom 2008)
> (random 100)
85
> (random 100)
73
> (random 100)
53
> (srandom 2008)
> (random 100)
85
> (random 100)
73
> (random 100)
53
Note however that Ikarus may itself use the random function for its
own purposes, so, the sequence received from random may not be
reproducible. Also, random may not have the behavior you'd expect (I
didn't work much on it), so, let me know if you encounter any
problems with it.
I also recommend that you try out Sebastian Egner's SRFI-27. The
interface is pretty good and the code is trustworthy.
Aziz,,,