----- Original Message ----- 
From: "Chris Wagner" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Saturday, December 03, 2005 5:11 AM
Subject: RE: rand() not so random


>  Spitting out the same
> 10 numbers next to each other still qualifies as a problem.  Still waiting
> for anyone from ActiveState to comment on this aspect of it.
>

Hmmm ... I don't really see that there's any obligation on their part to
make a comment - unless you can demonstrate that it's something that affects
ActiveState perl only. If there's something amiss with the perl source code
re rand(), then it should be best be taken up with the perl porters - or a
bug report should be filed (see perldoc perlbug). However, I don't believe
that there is anything amiss with rand(). Instead I think that if there is
an issue here, then it will prove to be a mod-perl issue - in which case it
should be taken up on a mod-perl forum.

That aside, it would help if you could provide a complete perl script that
demonstrates the precise "problem" quoted above.

I find no problem with the output of:

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";

It produced, for me:
8618 unique numbers. 1382 duplicates produced.

That's pretty much what you would get with truly random (15-bit) numbers.

With 16-bit numbers I get around 735 duplicates and with 25-bit numbers I
usually get 1 or 2 duplicates. With 30+ bit numbers duplication should be
very rare.

You could get 30-bit pseudo-random integers by doing:
my $fn = oct("0b" . sprintf("%b", rand(32768)) . sprintf("%b",
rand(32768)));

That's assuming $Config{randbits} is 15.

If you do that and you still get duplicates with 10,000 iterations, then we
know we've got a problem.

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to