Your skill will accomplishwhat the force of many cannot PerlMonks

### Re: list of random numbers with given avarage

by ChOas (Curate)
 on Mar 12, 2002 at 12:21 UTC ( #151095=note: print w/ replies, xml ) Need Help??

in reply to list of random numbers with given avarage

Hi!,

Sorry... not much time, have to go to a meeting, but I
whiped something up quickly

I`ll have another look later, but I like this one:
```#!/usr/bin/perl -w

use strict;

my \$Min=0;
my \$Max=100;
my \$Count=50;
my \$Average=50;
my \$RealAverage=0;
my \$Total=0;
my @Result;

for(1..\$Count)
{
#my \$New=int(rand(\$Max/2)+\$Min+((\$RealAverage>\$Average)||\$Average));
# Sorry, this line was totally screwed up, as it would
# give results outside the bounds given, substitute by
# this:

my \$New=int(rand(\$Max-\$Min))+\$Min;
\$New+=\$Average if (((\$New+\$Average)<\$Max)&&(\$RealAverage<\$Average));
\$New-=\$Average if (((\$New-\$Average)>\$Min)&&(\$RealAverage>\$Average));

\$Total+=\$New;
\$RealAverage=\$Total/\$_;
push @Result,\$New;
};

print join "\n",@Result;
print "\nAverage: \$RealAverage\n";

GreetZ!,
ChOas

print "profeth still\n" if /bird|devil/;
Comment on Re: list of random numbers with given avarage

Create A New User
Node Status?
node history
Node Type: note [id://151095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2016-05-25 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What font do you use for programming?

Results (328 votes). Check out past polls.