jbrugger has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks
I need your help again.The problem is the following:# srand(); # Generates collisions (no true random codes, also tried a +t the beginning of the code (not in the sub) # srand(time); # Generates collisions (no true random codes) sub GenCode { my $args = { AvailableChars => "ACDEFHIJKLMNPQRTUVWXYZ234679", CodeLength => 8, @_, }; # srand(); # Generates collisions (no true random codes, also tri +ed at the beginning of the code (not in the sub) # srand(time); # Generates collisions (no true random codes) srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); #seems to work +, but is slow. my $rndcode = ''; my @AvailableCharsA = split "", $args->{AvailableChars}; for (my $j=0;$j<$args->{CodeLength};$j++) { $rndcode .= $AvailableCharsA[int(rand(@AvailableCharsA-1))]; } return $rndcode; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: rand / srand
by BrowserUk (Patriarch) on Oct 24, 2006 at 07:51 UTC | |
|
Re: rand / srand
by spadacciniweb (Curate) on Oct 24, 2006 at 07:52 UTC | |
|
Re: rand / srand
by bingos (Vicar) on Oct 24, 2006 at 07:29 UTC | |
by xdg (Monsignor) on Oct 24, 2006 at 11:41 UTC | |
|
Re: rand / srand
by GrandFather (Saint) on Oct 24, 2006 at 07:45 UTC |