Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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
Download Code

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 romping around the Monastery: (6)
As of 2014-10-23 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls