Mail Archives: djgpp/1997/05/30/20:23:07
From: | aho450s AT nic DOT smsu DOT edu (Tony O'Bryan)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Random numbers
|
Date: | Fri, 30 May 1997 16:15:50 GMT
|
Organization: | Southwest Missouri State University
|
Message-ID: | <338efc9b.667005@ursa.smsu.edu>
|
References: | <01bc6ce9$72076bc0$363e63c3 AT 8652hvt73761>
|
NNTP-Posting-Host: | forseti.i99.smsu.edu
|
Lines: | 13
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
On 30 May 1997 11:09:48 GMT, "Matthew Bennett" <Bennett AT btinternet DOT com> wrote:
>printf("%d\n", random() & 10);
>
>The numbers produced are always either 0, 2, 8 or 10. If I use say 2 as my
This is because you are masking off all bits other than bits 1 and 3. This
leaves you with only {0,2,8,10} as the possible results. I think you meant to
use the modulus operator like so:
value = random() % 10;
This will get you a random number from 0 to 9.
- Raw text -