guile-devel
[Top][All Lists]
Advanced

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

Re: srand, rand


From: Mikael Djurfeldt
Subject: Re: srand, rand
Date: 09 Apr 2001 18:44:45 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Dirk Herrmann <address@hidden> writes:

> Is there any interest in adding scheme level functions for accessing the C
> level random functions?  I just wanted to set a C random seed from guile
> and had to define my own wrapper for srand.  This is probably a common
> situation for people who are linking guile to existing C code which uses
> rand() from the standard C library.

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.!)

Note that the random.c module contains a "plug-in" interface.  It was
put there exactly for the case where an application wants to use a
different generator than Guile's own (which BTW is very good and very
efficient).

Suggestion: We can add a function scm_set_rng_rand () which plugs in
the system's "rand" generator into Guile's plug-in interface.  An
application writer who then prefers to use the system "rand" functions
simply calls this function from his "inner_main" function...
(scm_set_rng_rand is easily implemented similarly to the first lines
of random.c:scm_init_random).

/mdj



reply via email to

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