Mail Archives: djgpp/1996/08/29/11:28:08
Errors-To: postmaster AT ns1
Xref: news2.mv.net comp.os.msdos.djgpp:7990
Newsgroups: comp.os.msdos.djgpp
From: macleod AT onyx DOT interactive DOT net (J.J. Pierson )
X-Newsreader: TIN [UNIX 1.3 unoff BETA release 960817]
X-Nntp-Posting-User: macleod
Sender: news AT interactive DOT net (System Administrator)
Organization: IBS Interactive, Inc.
Lines: 10
X-Trace: 841273893/19779
X-Nntp-Posting-Host: onyx.interactive.net
Date: Wed, 28 Aug 1996 23:11:34 GMT
Dj-Gateway: from newsgroup comp.os.msdos.djgpp
Content-Type: text
Content-Length: 576
Silly question... How would I go about getting a random number from say 1
to a specified number?
just call random(), after using srandom() to seed the generator, modulo the
result and add one. The following will give a number between 1 and 50
inclusive:
long num;
#define MAX_RAND 50
srandom( time(NULL) );
num = random();
num = (num % MAX_RAND) + 1;
--
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com
A proverb is no proverb to you 'till life has illustrated it. -- John Keats
- Raw text -