[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: srand, rand

From: Dirk Herrmann
Subject: Re: srand, rand
Date: Mon, 9 Apr 2001 19:05:47 +0200 (MEST)

On 9 Apr 2001, Mikael Djurfeldt wrote:

> There already exists a set of Scheme procedures and C level functions
> for producing random numbers in libguile/random.c.
> I think it's a little strange to supply a parallel set.
> One piece of background info regarding this is: It's always dangerous
> to use multiple pseudo-random number generators in an application.
> While a sequence of pseudo-random numbers appears "random" on it's
> own, it might not at all look random in relation to a sequence
> generated from another generator.  (A trivial example is this: Random
> number generators A and B are of the same type and generator B is
> seeded so that random number b_i from B = random number a_i-1 from A.)
> A good idea is therefore only to use a single generator.  (It should
> be the same for both C and Scheme levels, n.b.!)

While you are probably right in general, things are sometimes more
complicated.  The library that I have to use uses the following 'trick':  
It uses rand() to initialize a state for some other random number
generator, which is from libg++.  From then on, only that other random
number generator is used.  The point here is, that there are actually two
different random number generators being used.  I'd like to have control
of the random number sequence, and thus need to call srand before the
library initializes its random state.

It may be that all this is just bad practice, but I can't help it :-(

However, for guile the question remains open what the best way of doing
things is.  If, for example, guile is linked with different libraries each
of which uses a different random number generator, the user might still
want to influence each of them separately, even if this is, in theory, not
a good idea.


Best regards,
Dirk Herrmann

reply via email to

[Prev in Thread] Current Thread [Next in Thread]