About rand()

O Ilusionista

Captain 100K
Now I have doubt about it.

http://www.cplusplus.com/reference/cstdlib/rand/
v1 = rand() % 100;        // v1 in the range 0 to 99
v2 = rand() % 100 + 1;    // v2 in the range 1 to 100
v3 = rand() % 30 + 1985;  // v3 in the range 1985-2014

Notice though that this modulo operation does not generate uniformly distributed random numbers in the span (since in most cases this operation makes lower numbers slightly more likely).

But in OpenBOR:
rand()%100  starts from -100 to 100, or  am I crazy?
I often see people using random()%100+100 to get a positive value and not start with a negative one.

What is the right to do?

 
PS: I am aware of the pseudo random thing from rand() (the seed is updated once per second, not per call), so you can receive the same value sometimes.

Do OpenBOR accepts srand()?
 
O Ilusionista said:
PS: I am aware of the pseudo random thing from rand() (the seed is updated once per second, not per call), so you can receive the same value sometimes.

Do OpenBOR accepts srand()?

It does not, but I might be able to add it.

DC
 
I don't recall. I'll have to poke around my own notes when I get home.
 
I need that answer because I can't found information on google or this forum about that (9 years later :ROFLMAO:)
 
@O Ilusionista and @Toranks,

I've been cataloging all the script functions this morning, and I found there is in fact an srand(). It works by implementing the C srand32. I'm not the one who added it and I haven't tried it out yet, so you'll need to experiment yourself.

C:
int seed = <integer>;

int result = srand(seed);

DC
 
Back
Top Bottom