delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/05/07:38:07

From: ckeenan AT scsn DOT net (Chris)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random numbers/George
Date: Thu, 05 Jun 1997 09:00:34 GMT
Organization: All USENET -- http://www.Supernews.com
Lines: 51
Message-ID: <33967eab.25749893@supernews.scsn.net>
References: <2 DOT 2 DOT 32 DOT 19970604162434 DOT 0069d50c AT gate> <3395B097 DOT 5077 AT cornell DOT edu>
NNTP-Posting-Host: cola37.scsn.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Here is a bit of code from C for Dummies.  The book is terrible in
most parts, but this is a nice llittle thing it did.  It demonstrates
how to go about generating random numbers using the computers time.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int rnd(int range);
int seedrnd(void);

void main(void)
{
	int x;
	seedrnd();
	for (x=o;x<100;x++)
		printf("%i\t",rnd(10));
}

int rnd(int range)
{
	int r;
	r=rand()%range;
	return(r);
}

void seedrnd(void)
{
	srand((unsigned)time(NULL));
}



On Wed, 04 Jun 1997 14:14:47 -0400, "A. Sinan Unur" <asu1 AT cornell DOT edu>
wrote:

>Alan Wilson wrote:
> 
>> It sounds like to me that DJGPP doesnt have a truly random generator > then.
>> "Informal" random numbers are nice but it would be better if we could
>> generate truly random numbers where the frequency of all numbers were > the same...
>
>i guess ignorance is indeed bliss.
>
>this has nothing to do with DJGPP. as has been pointed out very clearly
>in previous responses to you, all computer generated random numbers are
>pseudo-random. (by the way, the only random distribution is _not_ the
>unifrom distribution.)
>
> -- Sinan

- Raw text -


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