Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mock random generator in BEGIN

use strict;
use warnings;
use 5.010;

BEGIN {
    my @values = (0.03, 0.72);
    *CORE::GLOBAL::rand = sub {
        return shift @values;
    };
}

use Test::More;
use MyRandomApp qw(dice);


is dice(10), 1;
is dice(10), 8;

my $x = rand;
is $x, undef, 'We have replaced rand here too';

done_testing;
prove -lv t/test-begin.t