public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bergner at vnet dot ibm dot com" <sourceware-bugzilla@sources.redhat.com> To: glibc-bugs@sources.redhat.com Subject: [Bug math/710] New: initstate() does not save the current position of the previous state array Date: Wed, 09 Feb 2005 16:46:00 -0000 [thread overview] Message-ID: <20050209164556.710.bergner@vnet.ibm.com> (raw) The initstate() call does not save the current position of the previous state, so if we switch back with setstate(), the sequence of random numbers generated id different than if we had never called initstate/setstate. This works on AIX, MacOSX and FreeBSD. The test case is simple: Peter-Bergners-Computer:~ peter$ cat rand.c #include <stdlib.h> #include <stdio.h> int main (int argc, char **argv) { int i; srandom(1); for (i=0; i < 10; i++) { printf("%d\n", (int)random()); if (argc >= 2) { /* This should not perturb the random number sequence above */ char *os, state[128]; os = initstate (1, state, sizeof(state)); setstate (os); } } return 0; } Expected result: [bergner@otta bergner]$ gcc rand.c [bergner@otta bergner]$ ./a.out 1804289383 846930886 1681692777 1714636915 1957747793 424238335 719885386 1649760492 596516649 1189641421 Incorrect result: [bergner@otta bergner]$ ./a.out 1 1804289383 940958272 77627160 1361779697 498448585 1782601122 919270010 55938899 1340091435 476760324 Correct result on MacOSX: Peter-Bergners-Computer:~ peter$ uname -v Darwin Kernel Version 7.7.0: Sun Nov 7 16:06:51 PST 2004; root:xnu/xnu-517.9.5.obj~1/RELEASE_PPC Peter-Bergners-Computer:~ peter$ gcc rand.c Peter-Bergners-Computer:~ peter$ ./a.out 1 1804289383 846930886 1681692777 1714636915 1957747793 424238335 719885386 1649760492 596516649 1189641421 -- Summary: initstate() does not save the current position of the previous state array Product: glibc Version: 2.3.4 Status: NEW Severity: normal Priority: P2 Component: math AssignedTo: aj at suse dot de ReportedBy: bergner at vnet dot ibm dot com CC: glibc-bugs at sources dot redhat dot com GCC build triplet: linux-i686 GCC host triplet: linux-i686 GCC target triplet: linux-i686 http://sources.redhat.com/bugzilla/show_bug.cgi?id=710 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
next reply other threads:[~2005-02-09 16:46 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-02-09 16:46 bergner at vnet dot ibm dot com [this message] 2005-02-09 16:49 ` [Bug math/710] " bergner at vnet dot ibm dot com 2005-02-10 9:40 ` cvs-commit at gcc dot gnu dot org 2005-02-16 4:19 ` roland at gnu dot org 2005-02-16 11:24 ` cvs-commit at gcc dot gnu dot org 2005-03-15 16:32 ` gbeauchesne at mandrakesoft dot com 2005-03-15 16:33 ` gbeauchesne at mandrakesoft dot com 2005-04-06 0:00 ` roland at gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20050209164556.710.bergner@vnet.ibm.com \ --to=sourceware-bugzilla@sources.redhat.com \ --cc=glibc-bugs@sources.redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).