Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "Dave Korn" To: Subject: RE: drand48() (and erand48) returns only zeros Date: Fri, 12 Nov 2004 18:01:02 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <20041112154151.37720.qmail@web52604.mail.yahoo.com> Message-ID: X-OriginalArrivalTime: 12 Nov 2004 18:01:02.0515 (UTC) FILETIME=[928D5830:01C4C8E1] > -----Original Message----- > From: cygwin-owner On Behalf Of meadmaker1066-cyg > Sent: 12 November 2004 15:42 > drand48 and erand48 return only 0.0 no matter how many > times I call them. The code works fine on the Linux > computers at school, and the compiler does not report > any errors or warnings. > Found this comment in newlib/libc/stdlib/rand48.c 144 Note that all three methods of seeding the random number generator 145 always also set the multiplicand and addend for any of the six 146 generator calls. Which somewhat implies that if you *don't* seed the rng, you get zero for multiplicand and addend. And indeed: dk AT mace /test/rand> cat randtest.cc #include #include #include using namespace std; int main (int argc, const char **argv) { if (argc > 1) { long int seed; if (1 != sscanf (argv[1], "%i", &seed)) { printf ("failure!\n"); return 0; } printf ("Seeding rng with %x\n", seed); srand48 (seed); } for(int i=0; i<10; i++) printf("%f\n",drand48()); return 0; } dk AT mace /test/rand> g++ randtest.cc -o randtest dk AT mace /test/rand> ./randtest.exe 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 dk AT mace /test/rand> ./randtest.exe 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 dk AT mace /test/rand> dk AT mace /test/rand> ./randtest.exe 100 Seeding rng with 64 0.251059 0.208948 0.940928 0.422546 0.395893 0.382565 0.231731 0.535547 0.533210 0.862949 dk AT mace /test/rand> ./randtest.exe 101 Seeding rng with 65 0.121861 0.913539 0.679373 0.888066 0.384079 0.598532 0.727126 0.157215 0.409803 0.484128 dk AT mace /test/rand> ./randtest.exe 100 Seeding rng with 64 0.251059 0.208948 0.940928 0.422546 0.395893 0.382565 0.231731 0.535547 0.533210 0.862949 cheers, DaveK -- Can't think of a witty .sigline today.... -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/