Advertisement

Random Numbers

Started by May 08, 2001 05:09 PM
2 comments, last by Squeejee 23 years, 9 months ago
Is there a function that can''t pick a random number between 2 numbers? I want something that will pick a number from 1 to 100. Thanks. ----------------------- Hail to the king, baby.
-----
randomize();
res = random(100) + 1;

or

srand(time(NULL));
res = rand()%100 + 1;

is this what you mean?

Arkon
[QSoft Systems]
Advertisement
I guess, if it picks a number between 1 and 100. And is "res" the variable that it stores the number in? Also, what include file is that in?

-----------------------
Hail to the king, baby.

Edited by - Squeejee on May 8, 2001 6:21:40 PM
-----
srand() and rand() are in stdlib.h

srand() seeds the algorithm to avoid that the same pattern is always repeated. You shouldn''t use a static number for seeding unless you really want to get the same returns in the same order everytime you run the program.


Snale
+--My humble and superior homepage

This topic is closed to new replies.

Advertisement