From f17c2202e4238b7408b8ee8ab742e5d2198cff6e Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 10 Feb 2005 09:40:23 +0000 Subject: [BZ #710] 2005-02-09 Jakub Jelinek [BZ #710] * stdlib/random_r.c (__initstate_r): Save old state. * stdlib/Makefile (tests): Add tst-random2. * stdlib/tst-random2.c: New test. Reported by Peter Bergner . (s390-.*-.*, powerpc.*-.*-.*, sparc.*-.*-.*): Add WORDSIZE64 entries for these mapping back to the above. --- stdlib/random_r.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'stdlib/random_r.c') diff --git a/stdlib/random_r.c b/stdlib/random_r.c index 09677e6..c85fd5e 100644 --- a/stdlib/random_r.c +++ b/stdlib/random_r.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1995 Free Software Foundation + Copyright (C) 1995, 2005 Free Software Foundation The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -240,10 +240,19 @@ __initstate_r (seed, arg_state, n, buf) int degree; int separation; int32_t *state; + int old_type; + int32_t *old_state; if (buf == NULL) goto fail; + old_type = buf->rand_type; + old_state = buf->state; + if (old_type == TYPE_0) + old_state[-1] = TYPE_0; + else + old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type; + if (n >= BREAK_3) type = n < BREAK_4 ? TYPE_3 : TYPE_4; else if (n < BREAK_1) -- cgit v1.1