Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!dkuug!diku!juul From: juul@diku.dk (Anders Juul Munch) Newsgroups: comp.lang.c++ Subject: Re: Random number generation Message-ID: <1991Mar14.204837.4448@odin.diku.dk> Date: 14 Mar 91 20:48:37 GMT References: <1991Mar11.151610.1984@linus.mitre.org> Sender: news@odin.diku.dk (Netnews System) Organization: Department of Computer Science, U of Copenhagen Lines: 21 ads@gateway.mitre.org (Alexas D. Skucas) writes: > Here is a C++ problem that is really giving me >headaches. I am trying to generate a random number >between 0 and 1. The rand function returns a huge >number (i.e 3.75658e+08) which I can't seem to be >able to deal with. I am running the Sun CC compiler. >ANY help would be extremely appreciated. Thanks. Apparently, rand() on your system returns a number between 0 and 2**32-1. Just divide by 2**32 and you get numbers evenly distributed between 0 and 1. The following function should do the trick: double rand01() { return rand()/4294967296.0; } -- Anders Munch