tags:

views:

34

answers:

2

Does seeding every time you use the random function with QueryPerformanceCounter() cause it to work poorly? Is there an algorithm for testing the quality of a random algorithm?

+2  A: 

As a rule, yes. You normally want to seed the generator once during program startup, and leave it alone after that. Re-seeding regularly with QPC is likely to make the results considerably more predictable -- QPC is almost constantly increasing and if you use it a few times without user-interaction in between, the difference between the two seeds may be nearly constant, even if the seeds themselves vary.

Jerry Coffin
I was just thinking, doesn't it cause the RNG algo to also be useless? Don't know how to explain it. But basically the function itself isn't changing the seed.
If your seed is predictable, the RNG is useless. There were high profile cases where this was exploited (early versions of Netscape and online poker sites come to mind). If your seed is not predictable, most modern RNG's are hard to exploit.
Eric J.
A: 

You don't say how often you are seeding, but if in a tight loop you should be aware that QueryPerformanceCounter() can be quite a slow call, and the time to make the call may vary from computer to computer (if they have different motherboards with different timing hardware).

So unless you have to call QueryPerformanceCounter() a lot (like you would in a profiler) don't do it.

You could just as well seed with GetTickCount() or timeGetTime() if you have to do multiple seeding.

Stephen Kellett