0

hi....i'm trying to write a code that generate random numbers quickly because i'll iterate my code a lot of times.....millions of times....
I use srand(time(NULL)) to initialize the seed, and random(RAND_MAX) to generate the random number, but this form is annormally slow
I need help to reduce the time of execution because millions of iterations retard too my program using "random"
Excuse me for my english...thanks!!!

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Salem
0

ok thanks, but I call srand() only once....i continue waiting for your responses thanks.....

0

rand() should be pretty quick, because it is pretty simple.

You might try

for ( i = 0 ; i < 1E7 ; i++ ) {
    num = 42;  // was num = rand();
}

Just to make sure that it's rand() which is the bottleneck, and not something else in your code.

You wouldn't be the first person to guess wrong as to where the performance issues really are.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.