Mail Archives: djgpp/2000/06/14/21:00:16
>How can I get a random number? Running DJGPP on Win95 machine.
Thanks.
This is part of the C standard library. First, you have to
include the stdlib.h header. This has 2 function prototypes
that you will need. Also, you will need time.h for the time
function.
By the way, these are only pseudo-random numbers, but I haven't
found that they are that unrandom. So first, you have to give
the rand function an initializer, you do this with the srand
function. I call srand(time(0)) for this. If you do not do
this, then the rand function will produce the same pattern of
numbers all the time.
Next, to get a random number, simply call rand(). And to get a
value that I can actually use, I perform a modulus division on
the result. So it looks like this: rand() % number.
Hope this helped. There are better random number generators
somewhere. I believe that there are some in the AllegrO
library, and also you might want to check out the snippets site,
they have everything else, there is a good possibility that they
will have random numbers.
- Dogansmoobs
Oh, so a microwave and a monitor are differant?? Excuse me
while I clean burrito off my monitor........
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
- Raw text -