ok I am doing little random coloring on c++/opengl…
But I got little problem when I use rand()…
so I made little program…
But after compile and running it several times I always get same numbers…
I know this is not opengl problem but this is the best coding forum…
#include <iostream.h>
int a,b,c;
float d,e,f;
void main(void)
{
f=3.2f;
a=(int)rand();
b=5+rand()%6;
c=(int)rand();
d=(float)rand()/3;
e=4*rand()%3;
//f=rand();
cout << rand() <<endl;
cout << b <<endl;
cout << c <<endl;
cout << d <<endl;
cout << e <<endl;
cout << f <<endl;
}
srand() is a function that will ‘seed’ the random number generator to ensure it generates different numbers each execution.
You only need to call it once in your initialisation code, most people usually use the time as a seed (then it varies indefinately, or until time ends if you believe in that).