delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/04/22:43:20

From: gautam AT interlog DOT com (Gautam N. Lad)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP random numbers
Date: Wed, 05 Mar 97 02:14:35 GMT
Organization: InterLog Internet Services
Lines: 31
Message-ID: <5fiko4$nmb@news.interlog.com>
References: <5f5nr3$8js AT news00 DOT btx DOT dtag DOT de>
NNTP-Posting-Host: ip226-210.cc.interlog.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,

>Sorry for asking that stupid question, but can anybody tell me how i can
>get random numbers from 0 to 255?
>
>Do i have to call something like a randomize timer function like in
>Borland?

I use srand() and rand() instead of the randomize() stuff.
You might have to include proper files for srand(), rand() and time(). 

Do this:

srand(time(NULL));
x=rand() % 255;	

Line 1) Initialize the seed using the system clock.
Line 2) Give variable x a random number between 0-255.

Bye!

****************************************************
* Gautam N. Lad                                    *
*--------------------------------------------------*
*                                                  *
* E-Mail	: gautam AT interlog DOT com              *
* Website	: http://www.interlog.com/~gautam  *
*                                                  *
* OS/2, DOS/Windows, Graphics Gallery, Software,   *
* Links, Rayzor Editor/2, POV-Ray,  and more.      *
****************************************************

- Raw text -


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