By adding use strict, fixing the errors flagged by strictures, fixing the indentation and using Perl rather than C I get the following (which may or may not do what you want):
#!usr/bin/perl use warnings; use strict; my $ntotal; for (1 .. 5000) { my $k = 25; my $N = 10000; my @cls; my $total = 0; while ($k >= 2) { my $mean = (4 * $N) / ($k * ($k - 1)); my $time = (-log (rand) * $mean); $ntotal += $time; push @cls, $time; --$k; } my $nmean = $ntotal / 5000; print "$nmean\n"; my @low = grep {$_ <= $nmean} @cls; my $nLow = scalar @low; my $hig = scalar (5000 - $nLow); print "$nLow\n"; print "$hig\n"; }
Prints:
2.37332066086488 0 5000 6.21051651542152 1 4999 8.59464183062829 0 5000 ...
In reply to Re: help finding mean, numbers above and below mean from an exponential distribution
by GrandFather
in thread help finding mean, numbers above and below mean from an exponential distribution
by kaupifalco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |