perl - How to test that a method generating random numbers does generate random numbers -


how can test method generating random numbers generates random numbers? there ($tested_method, rand) sort of syntax?

specifically, i'm referring ping generator method:

sub _create_ping_number {    ( $ping, @random_array );    $max            = 100000;    $random_counter = 0;     if ( $random_counter == $max ) {      @random_array   = ();      $random_counter = 0;    }     until ( !undef( $random_array[ $ping = int( rand($max) ) ] ) ) { }       $random_array[$ping] = 1;       $random_counter++;       return $ping; } 

the links in comment mob provide detail on how difficult assert data source random.

for unit test, may better off using srand in test setup (making technically "white box" test), , relying on fact behaviour of rand() known. normal practice far know, unless want test prng or entropy source have written.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -