delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/05/06:33:53

Message-Id: <2.2.32.19970305155059.006a8c1c@mailhost>
Mime-Version: 1.0
Date: Wed, 05 Mar 1997 13:50:59 -0200
To: djgpp AT delorie DOT com
From: Eyal Ben-David <eyalb AT aks DOT com>
Subject: Re: DJGPP random numbers

>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?
>

random_number_0_to_255 = rand() % 256;

the declaration for rand() is in stdlib.h

It is usually good to seed the random number generator. Otherwise it would
create the same sequence of "random" numbers every time.

You can do it at the begining of your program for example:

        time_t now;
        now = time(NULL);   /*  or:  time(&now);
        srand(now);


Eyal.

- Raw text -


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