The approach of keeping track of the numbers you have already generated and then generating a new one if you've already given out that one is appropriate with the total number of random numbers that you need is much less than the range of numbers you're generating between.
As it is in this case - unless the MS PRNG is so poor that the period is so small that 600 is a relatively large compared to the range.
I suspect that in the OP's case the performance is of o(n) but that would require either some maths or simulation to confirm. :) It would also depend on how many of the 600 is needed. If it is e.g. only 5 out of 600 with no repeats, then that would be different to getting 550 out of 600 with no repeats.
Regards David R
---------------------------------------------------------------
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
Every program eventually becomes rococo, and then rubble. - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
No comments:
Post a Comment