> -----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:


[EMAIL PROTECTED] /test/rand> cat randtest.cc
#include <stdlib.h>
#include <cmath>

#include <iostream>
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;
}

[EMAIL PROTECTED] /test/rand> g++ randtest.cc -o randtest
[EMAIL PROTECTED] /test/rand> ./randtest.exe
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
[EMAIL PROTECTED] /test/rand> ./randtest.exe
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
[EMAIL PROTECTED] /test/rand>
[EMAIL PROTECTED] /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
[EMAIL PROTECTED] /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
[EMAIL PROTECTED] /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/

Reply via email to