K
kkirtac
Hello, i m using the standard rand() function to generate several
random numbers. Even if i seed the generator before the loop
"srand( (unsigned)time( NULL ) );" , it usually selects a previously
selected number in the process, after 6-7 iterations, i want the
sequence to be unique..should i consider some further modifications in
the code to achieve my goal maybe ? here is the piece of code..
vector<int> rands ;
int rnd ; //random number
srand( (unsigned)time( NULL ) );
int range_max = 165, range_min = 0 ;
for( int i = 0; i < 15 ; i++ )
{
rnd = (double)rand() / (RAND_MAX + 1) * (range_max-1 -range_min) +
range_min;
rands.push_back(rnd);
}
it usually chooses a previously selected random number after 7-8
iterations, not all the time but usually..
Regards,
random numbers. Even if i seed the generator before the loop
"srand( (unsigned)time( NULL ) );" , it usually selects a previously
selected number in the process, after 6-7 iterations, i want the
sequence to be unique..should i consider some further modifications in
the code to achieve my goal maybe ? here is the piece of code..
vector<int> rands ;
int rnd ; //random number
srand( (unsigned)time( NULL ) );
int range_max = 165, range_min = 0 ;
for( int i = 0; i < 15 ; i++ )
{
rnd = (double)rand() / (RAND_MAX + 1) * (range_max-1 -range_min) +
range_min;
rands.push_back(rnd);
}
it usually chooses a previously selected random number after 7-8
iterations, not all the time but usually..
Regards,