From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rick Dearman To: help-gcc@gnu.org Subject: Re: gcc newbie: rand() Date: Sun, 12 Dec 1999 15:35:00 -0000 Message-id: <385430E6.9133F3C5@ricken.demon.co.uk> References: <3850EBFA.BE9086DC@singnet.com.sg> X-SW-Source: 1999-12/msg00193.html Try this: #include #include int get_rand(int range) { int mrand; mrand = (int)((double)rand() / ((double)RAND_MAX +1) * range); return mrand; } int main(void) { float x; int n; srand((unsigned int)time((time_t *)NULL)); x = (float)( get_rand(5) / 32768.0 ); n = 1 + (int) (6*x); printf("x = %d\n", n); return 0; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rick Dearman To: help-gcc@gnu.org Subject: Re: gcc newbie: rand() Date: Fri, 31 Dec 1999 22:24:00 -0000 Message-ID: <385430E6.9133F3C5@ricken.demon.co.uk> References: <3850EBFA.BE9086DC@singnet.com.sg> X-SW-Source: 1999-12n/msg00193.html Message-ID: <19991231222400.Nuwc1UjRSEIh4RhEpSCj0EWAyL-TDHl8CPjB1h-HLhU@z> Try this: #include #include int get_rand(int range) { int mrand; mrand = (int)((double)rand() / ((double)RAND_MAX +1) * range); return mrand; } int main(void) { float x; int n; srand((unsigned int)time((time_t *)NULL)); x = (float)( get_rand(5) / 32768.0 ); n = 1 + (int) (6*x); printf("x = %d\n", n); return 0; }