#!/usr/bin/perl use strict; use warnings; use feature 'say'; sub say_rand { say rand for 0..4 } # Our initial state, fatalsrand is enabled by default # Upstream will be that they won't enable it by default # But they could enable it with `use feature ':5.30';` say "default"; say rand for 0..4; { # Inside this block, we disable the feature no feature "arc4random"; # and set a seed srand(1); say "first srand(1), we get fake random"; say rand for 0..4; # repeating the seed so we see the same values srand(1); say "second srand(1), more fake random"; say rand for 0..4; # repeating the seed so can tell it doesn't effect subs srand(1); say "in a sub, have real random"; say_rand(); # resetting it once more so it's easy to see # that it doesn't effect outside the block. srand(1) } # here we are outside of scope of no feature "fatalsrand" say "outside the block, we again have real random"; say rand for 0..4; # but we can set an srand with a 0 value or no argument srand(0); say "with srand(0), not fatal and get real random"; say rand for 0..4; # But, trying to set with an argument is fatal. srand(1); say "dead, we never got here, so no random"; say rand for 0..4; __END__ Unsurprisingly specific tests of random things failed. Fortunately not a significant number and mostly those will be solved with `no feature 'arc4random'`. Failed 8 tests out of 2271, 99.65% okay. ../dist/Math-BigInt-FastCalc/t/mbi_rand.t ../dist/Math-BigInt/t/mbi_rand.t ../dist/Tie-File/t/27_iwrite.t ../dist/Tie-File/t/28_mtwrite.t ../lib/warnings.t op/rand.t op/srand.t porting/diag.t But, it seems t do what I want: $ LD_LIBRARY_PATH=./ ./perl -Ilib /home/afresh1/fatalsrand/test_fatal_srand.pl default 0.271240094210953 0.447951349895447 0.455521963536739 0.322725609876215 0.727832014672458 first srand(1), we get fake random 0.0416303447718782 0.454492444728629 0.834817218166915 0.3359860301452 0.565489403566136 second srand(1), more fake random 0.0416303447718782 0.454492444728629 0.834817218166915 0.3359860301452 0.565489403566136 in a sub, have real random 0.300016483291984 0.719882455887273 0.838353087427095 0.578636008314788 0.887329616816714 outside the block, we again have real random 0.4700819903519 0.0622672068420798 0.79616755945608 0.349847834091634 0.826718745520338 with srand(0), not fatal and get real random 0.353320164373145 0.187837267760187 0.320199340581894 0.475815023994073 0.785070860292763 srand with seed not allowed with arc4random at /home/afresh1/fatalsrand/test_fatal_srand.pl line 48.