delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/11/12/13:02:37

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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" <dk AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: drand48() (and erand48) returns only zeros
Date: Fri, 12 Nov 2004 18:01:02 -0000
MIME-Version: 1.0
In-Reply-To: <20041112154151.37720.qmail@web52604.mail.yahoo.com>
Message-ID: <NUTMEGmjpD3zCParqjP000006cd@NUTMEG.CAM.ARTIMI.COM>
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 <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;
}

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019