http://www.perlmonks.org?node_id=1052881

perlaintdead has asked for the wisdom of the Perl Monks concerning the following question:

I posted a very simple (and apparently bad) RNG and got a lot of good advice so here is my next shot at an RNG. Only problem is the numbers start too repeat after 5 iterations. not exactly a finished product and will try to make the seed more random latter but for now i just need to know why it repeats.

fixed
use warnings; use strict; use Digest::SHA 'sha384_hex'; my $randseed; my $randNum; my $salt = "salty"; print RandomMutation()."\n" for 0..100; sub RandomMutation{ $randseed = trim( convertToAscii( sha384_hex( crypt( rand(100000), + $salt) . localtime()) ) ); srand( $randseed ); $randNum = int rand 10000; $salt = trim( ( ( ( ($randNum / 2) + ($randseed * 1.427) + ($$ * 4 +) ** 2)) * 1.618) ); return $randNum; } sub convertToAscii{ my $convertToAscii = shift; my $ConvertedAscii = ""; foreach(split //, $convertToAscii){ $ConvertedAscii = $ConvertedAscii . ord $_ ; } return $ConvertedAscii; } sub trim{ my $TrimNum = shift; $TrimNum = substr $TrimNum, 5, 9; return $TrimNum; }