From mboxrd@z Thu Jan 1 00:00:00 1970 From: martin.kahlert@keksy.mchp.siemens.de (Martin Kahlert) To: help-gcc@gnu.org Subject: Re: gcc newbie: rand() Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: <82qv9p$34v$1@news.mch.sbs.de> References: <3850EBFA.BE9086DC@singnet.com.sg> X-SW-Source: 1999-12n/msg00163.html Message-ID: <19991231222400.bWXX0KJk5LOHMnmObHAGGK7E2d1BYJYdKQin9IvBw6A@z> In article < 3850EBFA.BE9086DC@singnet.com.sg >, Joachim Bauernberger 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.