Nicholas Clark wrote at Fri, 02 Aug 2002 11:06:47 +0200: >> srand could be our friend. > > Which is how I'm doing it at work now. > I call srand with a random number. (I'm getting mine from /dev/urandom, > but I suspect that calling rand() and using that to prime srand will > achieve sufficient randomness for these purposes. (ie you get to run one > of 65536 sequences, which is better than running 1 of 1 sequence) > > My tests at work generate a seed this way before starting. They call srand > with the seed, and store the seed. > If the test fails, they print out what the seed was on STDERR. > (as a hack in an END block that checks the exit code after Test::Builder > has set it in its END block)
With a "most_ok" function realising randomness test, I would only need to check the result of this function :-)) > If the test is run with no arguments it randomises (as above). Else it > treats the argument as a chosen seed, and uses that to call srand() to > repeat a previous run. > > This way I can make test a few times and it runs different random parameters > each time. And if a test fails, it prints out the seed, and I can re-run > repeatedly by hand until I work out why there is a bug. And fix it. Very elegant. I'll follow that way. [Allthough, I believe I'll take a syntax like use Test::ManyParams; # like srand(0) or srand(42) use Test::ManyParams 'randomized' # with srand(rand()) use Test::ManyParams 'randomized', $seed; # srand($seed) to hide the hacks] Thank you, Greetings, Janek