Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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/;

Log In?
Username:
Password:

What's my password?
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 exploiting the Monastery: (8)
As of 2016-10-01 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (7 votes). Check out past polls.