I think that your range testing is suspect.
That is, the test should be that the end is less than or equal to $some_pos
Ie. If $some_pos = 950; then a range of [0, 901] would fail:
$some_pos = 950; print +( $_->[1] < $_->[0] and $_->[1] >= $some_pos ) ? 'contained' : 'not contained' for [0, 901];; not contained
However, neither of those affect the discrepancy you note.
I also thought that using a better rand() might change things, but as you note, Math::Random::MT shows the same discrepancy.
Then I thought perhaps the difference might be due to sample .v. population variance; and discovered that there appears to be an undocumented parameter to the variance() method that might be intended to affect the calculation:
sub variance { my $self = shift; ##Myself my $div = @_ ? 0 : 1; ... $variance /= $count - $div;
Ie. If you pass any parameter(s) to the variance method, it appears (I think) to calculate the population rather than the sample variance? Update: the variations are the biased versus unbiased estimates of variance.
But as expected, whilst it does make some slight difference, it is very small:
[21:59:37.22] C:\test>874353 10000: 10.003 9.138 10.0028 9.13839215999999 [21:59:44.34] C:\test>874353 10000: 10.003 9.139 10.0028 9.13930609060905
At this point, I see two possibilities that I don't have answers to, or the knowledge to verify:
I don't recall ever seeing it stated that variance and mean should coincide for such data?
Could the calculation of the variance be affected by a) the inclusive nature of the ranges; or b) the wrap-around?
Not much help, but it might trigger some thoughts somewhere.
In reply to Re: Unexpected under-dispersion in random simulations
by BrowserUk
in thread Unexpected under-dispersion in random simulations
by daverave
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |