Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (48 sloc) 2.079 kB
Test::Random - Make testing random functions deterministic
use Test::Random;
... test as normal ...
This is a testing module to make testing random things a bit more
Controlling randomness
Its main function is to allow you to repeat a failing test in the same
way it ran before, even if it contained random elements. Test::Random
will output the seed used by the random number generator. You can then
use this seed to repeat the last test with exactly the same random
You can control the random seed used by Test::Random by setting the
"TEST_RANDOM_SEED" environment variable. This is handy to make test runs
TEST_RANDOM_SEED=12345 perl -Ilib t/some_test.t
Test::Random will output the seed used at the end of each test run. If
the test failed it will be visible to the user (ie. on STDERR) otherwise
it will be a TAP comment and only visible if the test is run verbosely.
If having new data every run is too chaotic for you, you can set
TEST_RANDOM_SEED to something which will remain fixed during a
development session. Perhaps the PID of your shell or your uid or the
date (20090704, for example).
When you run a test with Test::Random you will see something like this:
perl some_test.t
ok 1
ok 2
ok 3
# TEST_RANDOM_SEED=20891494266
If you wish to repeat the circumstances of that test, with the same
randomly generated data, you can run it again with the
"<TEST_RANDOM_SEED"> environment variable set to the given seed.
TEST_RANDOM_SEED=20891494266 perl some_test.t
ok 1
ok 2
ok 3
# TEST_RANDOM_SEED=20891494266
See your shell and operating system's documentation for details on how
to set environment variables.
If something in your code calls srand() all bets are off.
Test::RandomResults, Test::Sims, Data::Random, Data::Generate
Jump to Line
Something went wrong with that request. Please try again.