6 set_up_inc( qw(. ../lib) );
15 # Generate a load of random numbers.
16 # int() avoids possible floating point error.
17 sub mk_rand { map int rand 10000, 1..100; }
20 # Check that rand() is deterministic.
22 my @first_run = mk_rand;
25 my @second_run = mk_rand;
27 ok( eq_array(\@first_run, \@second_run), 'srand(), same arg, same rands' );
30 # Check that different seeds provide different random numbers
35 @second_run = mk_rand;
37 ok( !eq_array(\@first_run, \@second_run),
38 'srand(), different arg, different rands' );
41 # Check that srand() isn't affected by $_
48 @second_run = mk_rand;
50 ok( !eq_array(\@first_run, \@second_run),
51 'srand(), no arg, not affected by $_');
54 # This test checks whether Perl called srand for you.
56 local $ENV{PERL_RAND_SEED};
57 @first_run = `$^X -le "print int rand 100 for 1..100"`;
58 sleep(1); # in case our srand() is too time-dependent
59 @second_run = `$^X -le "print int rand 100 for 1..100"`;
62 ok( !eq_array(\@first_run, \@second_run), 'srand() called automatically');
64 # check srand's return value
65 my $seed = srand(1764);
66 is( $seed, 1764, "return value" );
69 ok( $seed, "true return value for srand(0)");
70 cmp_ok( $seed, '==', 0, "numeric 0 return value for srand(0)");
76 local $SIG{__WARN__} = sub {
82 is( $b, 0, "Quacks like a zero");
83 is( "@warnings", "", "Does not warn");
90 local $SIG{__WARN__} = sub { $w .= $_[0] };
92 like($w, qr/^Integer overflow in srand at /, "got a warning");