Link to home
Start Free TrialLog in
Avatar of mrmind3
mrmind3

asked on

Generating different sequences of random numbers

When I use randomize() and rand(), I get a sequence of random numbers in the range I need. However, I need to generate about a 1000 DIFFERENT sequences of random numbers in the given range. About 500 or so runs result in 500 same sequences since randomize() uses the system clock as a seed and 500 runs take less than a second to execute. In other words, since my program runs faster than the seed (clock seconds) can change, I get a lot of same sequences of random numbers. I tried slowing down the program by inserting loops but then it runs too slow. Is there anyway to get a 1000 different sequences?
Avatar of nietod
nietod

On a windows computer you could use GetTickCount as a seed.

Are you seeding the randome number more than once per run of the program?  it sounds like you are.  There is no need.  Just seed 1 time, when the program starts and you won't get any repeats.
Avatar of mrmind3

ASKER

But I do need to seed several times. I need to get  about a 1000 DIFFERENT sequences of random numbers not just one sequence.
You could XOR all the generated random numbers, and use this as the next seed.
And perform some bit-swapping, or whatever, depending if the number is odd or even or so. This will for sure make 1000 different random sequences.
Avatar of ozo
randomize() once
then get 1000 different sequences of rand()
This is what nietod also proposed, but mrmind3 wants to be able to start every sequence with a new seed.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree, but the second sequence of 4 numbers is affected by the first sequence, coz the rand() function is implemented in the way it has memory over the last generated numbers.
If you want to be technical about it the numbers aren't random in either case.  But in either case the numbers will be evenly disrtibuted over the integer range and will display any easily detectable pattern.  So there is no difference in either case.  They are equally "random"