6 use Test::More tests => 5;
8 # Generate a load of random numbers.
9 # int() avoids possible floating point error.
10 sub mk_rand { map int rand 10000, 1..100; }
13 # Check that rand() is deterministic.
15 my @first_run = mk_rand;
18 my @second_run = mk_rand;
20 ok( eq_array(\@first_run, \@second_run), 'srand(), same arg, same rands' );
23 # Check that different seeds provide different random numbers
28 @second_run = mk_rand;
30 ok( !eq_array(\@first_run, \@second_run),
31 'srand(), different arg, different rands' );
34 # Check that srand() with no args provides different seeds.
39 @second_run = mk_rand;
41 ok( !eq_array(\@first_run, \@second_run), 'srand(), no arg, different rands');
44 # Check that srand() isn't effected by $_
51 @second_run = mk_rand;
53 ok( !eq_array(\@first_run, \@second_run),
54 'srand(), no arg, not effected by $_');
59 # This test checks whether Perl called srand for you.
60 @first_run = `$^X -le "print int rand 100 for 1..100"`;
61 @second_run = `$^X -le "print int rand 100 for 1..100"`;
63 ok( !eq_array(\@first_run, \@second_run), 'srand() called automatically');