[erlang-questions] random:seed in R14, R15, ...

Samuel samuelrivas@REDACTED
Thu Jul 19 08:37:27 CEST 2012


> When writing test cases that exercise e.g. random:uniform/0 one wants to use random:seed/1 with a fixed seed for deterministic test results, but providing the seed function with a fixed value seems to result in a different sequence for R14 and R15 (maybe for older or upcoming release as well). This is a problem when distributing your code and you are not sure which release will be used.
>
> What is the common solution for this?

For randomised tests cases I usually seed the generator with now() as
I would do for normal pseudorandom usage, but I write the tests so
that, if failed, I get the originating seed in the report. That means
that the tests are not deterministic in general, but deterministic
enough to replay if needed. In theory, that way you also increase the
chances of finding a weird failing sequence by repeating the tests
over and over.

It is similar to the strategy used by QuickCheck, which is a bit more
advanced. There you don't control the seed either, but when something
fails it reports the counterexample back, so you don't need the seed.

In general, if you are testing with pseudorandom generators is because
you want to increase the coverage in a state space to big to be
covered by just exploring the possible combinations, so you don't want
to restrict your random sequences to just one.

Regards
-- 
Samuel



More information about the erlang-questions mailing list