5 ms·
It's probably the fact that using time() for seeding a PRNG is a really poor choice.
by detrino 12y ago
It's probably the fact that using time() for seeding a PRNG is a really poor choice.
- pdw 12y agoEspecially if your clock is synced with every other clock in the world.
- aidenn0 12y agoHere's what happens when you do that: http://alt.org/nethack/player-all.php?player=WowDeath http://alt.org/nethack/player-all.php?player=WowDeath Full article here: http://taeb-nethack.blogspot.com/2009/03/predicting-and-controlling-nethacks.html http://taeb-nethack.blogspot.com/2009/03/predicting-and-cont...
- deleted 12y ago[deleted]
- kevin_thibedeau 12y agoIt isn't a problem if all you need is a deterministic sequence of numbers that are pseudo-random like what rand() provides. Not every use of a PRNG involves cryptographic security or potentially dangerous exposures of internal state.
- detrino 12y agoThere are concerns with using time() as a seed other than security. Besides, consider what you are typically trying to express: initialize my PRNG with a random seed. Almost never are you trying to express: initialize my PRNG so that all runs in the same second will behave identically.
- kevin_thibedeau 12y agoIf you're generating random test case input on a single machine, time() is a perfectly reasonable way to seed a PRNG. A super-robust entropy source isn't a necessity when you just want something nominally random between intermittent runs.
- deleted 12y ago[deleted]
- nitrogen 12y ago...nominally random between intermittent runs. That's a lot of caveats. Suppose you want to run multiple times in one second. Suppose you want statistically uniform random numbers to ensure even coverage of test cases.
- xorcist 12y agoAlso if your clock resets on boot for some reason, and boot time is predictable.
- CHY872 12y agoFor test case generation, I'd argue that you want the opposite of a time initialised random number generator. You'd want a deterministic seed for your random number generator, so you can repeat if required.
- panzi 12y agoWhy don't you use this sequence in such a case?: 0, 1, 2, 3, 4, 5, 6, 7, 8, ...
- craftkiller 12y agooh thats also a good point, but it would be solved with arc4random :-)
- wglb 12y agoIn some cases, yes. Some simulations want to have the same sequence of numbers. Seems like a fundamental design misunderstanding in nethack, however.
- detrino 12y ago> Some simulations want to have the same sequence of numbers. srand(time(NULL)); does not provide that.
- jerf 12y agoThe point is, if you want a repeatable sequence, ask for it. If you want a truly random sequence, ask for it. What you don't want is a repeatable random sequence that you, the programmer, incorrectly think is truly random. But rather a lot of invocations to srand turn out to be this case, rather than either of the legitimate two.