delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/30/13:54:18

From: "Matthew Bennett" <Bennett AT btinternet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Random numbers
Date: 30 May 1997 11:09:48 GMT
Organization: Server Status Page : http://www.btinternet.com/~bennett/status.html
Lines: 22
Message-ID: <01bc6ce9$72076bc0$363e63c3@8652hvt73761>
NNTP-Posting-Host: host5-99-62-54.btinternet.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi all,

When using the 'random' command in the form:

printf("%d\n", random() & 10);

The numbers produced are always either 0, 2, 8 or 10. If I use say 2 as my
range, the numbers produced are only 0 or 2.  I don't seem to be able to
get a well varied set of random numbers (i.e. all the numbers in the range
eventually appear). Using the command form:

prinf("%d\n", random(10));

produces the same sequence of very large numbers - whatever range I use.

Does anyone know how I can get a sequence of in-range, varied numbers?
For what I'm writing, it would also need to be seeded (the 'srandom'
command is what I'm currently using).

Thanks,

Matthew

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019