> I know it "shouldn't" make a difference, but we all know that things that
> shouldn't, do. I wasn't seeding it explicitly, was letting perl handle
> it.
> Unless it's a bug, my theory is that mod_perl is keeping the old seed from
> the last compile. Mod_perl does not recompile or even reinitialize the
> script between calls. I've used this effect to maintain data within the
> cgi
> script.
>
> The code is trvial.
> my $fn = substr rand(), 2;
> my $x = 0;
> while (-e "$tempdir\\$fn.bat") {
> print "<!-- batch file $tempdir\\$fn.bat already exists -->\n";
> $fn = substr rand(), 2;
> print "cannot find unique temp bat file" and die "cannot find unique
> temp bat file" if $x > 10;
> $x++;
> }
>
> The change I made was to put srand() above rand(). It's build 811. But
> really, that's all beside the point. The core problem is rand() repeating
> it's output.
>
> Just for fun I did a little test.
> for (1 .. 10000) {
> my $fn = rand();
> ++$dup and next if exists $num{$fn};
> $num{$fn} = 1;
> }
> print scalar keys %num, " unique numbers. $dup duplicates produced\n";
> #########
> 8623 unique numbers. 1377 duplicates produced
>
> That's really interesting. So rand() is pretty useless.
random <> unique.
If you want unique numbers also put your routine above in
your program and discard duplicates.
>
> At 10:00 PM 11/29/2005 -0600, John Garvin wrote:
>>perldoc -f srand says srand() is called implicitly the first time
>>rand() is called, so your change shouldn't make a difference.
>>
>>How were you seeding rand() before?
>>
>>Got any code to show us?
>
>
>
>
> --
> REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=--
> "...ne cede malis"
>
> 00000100
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs