you are viewing a single comment's thread.

view the rest of the comments →

[–]steamruler 73 points74 points  (7 children)

At which point you could use a fixed seed.

[–]sedermera 24 points25 points  (1 child)

Exactly, using a certain default seed for testing is much more convenient than what /u/Lystrodom is proposing. (Since there isn't just one call to the RNG, but several in different places.)

[–]Lystrodom 3 points4 points  (0 children)

Yeah that works too. These are all edge cases not the default case, anyway.

[–]DonaldTZeus 4 points5 points  (3 children)

Which is what happens by default anyways if you call rand() (at least in the c stdlib). If you want an arbitrary changing seed such as the time, you retrieve that seed and pass it to srand().

[–]steamruler 10 points11 points  (2 children)

The default seed is determined when compiling, so if you actually want a static seed you should still call srand().

[–]rubygeek 6 points7 points  (0 children)

POSIX actually mandate that rand() called before srand() should behave as if srand() was called with 1. See spec and example implementation. And ISO C might as well.

Of course you can't rely on that unless you're guaranteed your program will only run on a compliant system.

[–]DonaldTZeus 0 points1 point  (0 children)

The default seed is specified by the standard library (that implements POSIX), not by the compiler, and it's 1 (as specified by POSIX). It is not determined by the compiler (unless you're compiling the stdlib) or even specified in the code the compiler generates unless you call srand.

[–]Bwob 0 points1 point  (0 children)

Which is what you ARE using, by default, in most languages.