diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-12-17 21:09:26 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-12-17 21:09:26 -0800 |
commit | 0e696e94cdf30c3b5a14a36f2636d1cfe55d5d34 (patch) | |
tree | 5ee9ad31559caf490cccfc1790d57c7740a3232f /rand.c | |
parent | 293366c3410893f6937b507e2ca1f7ab192f1ad2 (diff) | |
download | txr-0e696e94cdf30c3b5a14a36f2636d1cfe55d5d34.tar.gz txr-0e696e94cdf30c3b5a14a36f2636d1cfe55d5d34.tar.bz2 txr-0e696e94cdf30c3b5a14a36f2636d1cfe55d5d34.zip |
* rand.c (rand32): Bugfix: if the seed object is a random
state, we do not want to make the 8 calls to rand32 to
mix up the state; we need are making a straight copy.
* txr.1: Document the possibility that the seed object
is a random state. Document the platform-independence of the
integer seed.
Diffstat (limited to 'rand.c')
-rw-r--r-- | rand.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -110,12 +110,10 @@ static rand32_t rand32(struct rand_state *r) val make_random_state(val seed) { val rs = make_state(); - int i; + int i, copy = 0; struct rand_state *r = coerce(struct rand_state *, cobj_handle(rs, random_state_s)); - r->cur = 0; - seed = default_bool_arg(seed); if (bignump(seed)) { @@ -159,13 +157,17 @@ val make_random_state(val seed) struct rand_state *rseed = coerce(struct rand_state *, cobj_handle(seed, random_state_s)); *r = *rseed; + copy = 1; } else { uw_throwf(error_s, lit("make-random-state: seed ~s is not a number"), seed, nao); } - for (i = 0; i < 8; i++) - (void) rand32(r); + if (!copy) { + r->cur = 0; + for (i = 0; i < 8; i++) + (void) rand32(r); + } return rs; } |