fix: Splat_random Macro not so random

This commit is contained in:
Wouter van Oijen 2006-07-24 20:27:29 +00:00
parent f420103b2e
commit 4e2e5e8c78
4 changed files with 27 additions and 18 deletions

View file

@ -35,6 +35,8 @@
line, which fixed a problem with the WRE monitor, and also enabled us to
add more complete connectivity testing.
- fix: Templates XHTML compliance (Wouter van Oijen / ProcoliX)
- fix: Splat_random Macro not so random (Wouter van Oijen / ProcoliX) (Thanks
to Colin Kuskie for pointing this out and writing some tests)
7.0.2

View file

@ -8,6 +8,18 @@ versions. Be sure to heed the warnings contained herein as they will
save you many hours of grief.
7.0.3
--------------------------------------------------------------------
* Numbers generated by the Splat_random macro were not evenly
distributed. It returned numbers between 0 and 'max' (inclusive)
with this two numbers occuring about half as much as other numbers.
This is now fixed, so it will return numbers between 0 and 'max-1'
(inclusive), with an equal probability of any of these numbers.
If you're using this macro, you might need to increment the max
parameter.
7.0.2
--------------------------------------------------------------------

View file

@ -21,32 +21,30 @@ Package WebGUI::Macro::Splat_random
Macro for returning a bounded, integer random number.
#-------------------------------------------------------------------
=head2 process ( max )
Random numbers are rounded, not truncated.
Random numbers are truncated to integer values.
=head3 max
The maximum random number. If omitted, 1_000_000_000 is
The upper bound for the random number. If omitted, 1_000_000_000 is
used as a default.
=cut
#-------------------------------------------------------------------
sub process {
my $session = shift;
my ($temp, @param, $limit);
@param = @_;
if ($param[0] ne "") {
$limit = $param[0];
} else {
$limit = 1000000000;
}
$temp = round(rand($limit));
return $temp;
my (@param, $limit);
@param = @_;
if ($param[0] ne "") {
$limit = $param[0];
} else {
$limit = 1000000000;
}
return int(rand($limit));
}
1;

View file

@ -71,9 +71,6 @@ WHOLE: for (my $i=0; $i<=999; $i++) {
++$bins[$output];
}
is(scalar(@bins), 5, "All bins have values on a sample size of 1000");
is(scalar(@bins), 4, "All bins have values on a sample size of 1000");
##Early work in analyzing a frequency distribution showed that the highest
##and lowest bin have half the frequency of center bins. Splat_random doesn't
##seem very random
#diag Dumper \@bins;