gcc newbie: rand()
Martin Kahlert
martin.kahlert@keksy.mchp.siemens.de
Fri Dec 10 22:18:00 GMT 1999
In article < 3850EBFA.BE9086DC@singnet.com.sg >,
Joachim Bauernberger <nuklear@singnet.com.sg> writes:
> /* hi there!
> *
> * can anybody tell my why the following code compiled with:............
>
> * gcc -g -D_GNU_SOURCE filename.c -o outputfile
> *
> * ....generates all sort of strange numbers but when compiled under
> borland gives me the desired * random numbers between 1 and 6 ??? how
> do i do it to get the numbers between 1 and 6.
> * this example is from a book about C so it can't be that wrong, can
> it?
It's wrong because of the strange value 32768. Use
x = rand() / (double) RAND_MAX;
instead.
--
The early bird gets the worm. If you want something else for
breakfast, get up later.
More information about the Gcc-help
mailing list