Hacker News new | past | comments | ask | show | jobs | submit login

It 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.



There 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.


If 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.


For 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.


...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.


Also if your clock resets on boot for some reason, and boot time is predictable.


Why don't you use this sequence in such a case?: 0, 1, 2, 3, 4, 5, 6, 7, 8, ...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: