Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: list of random numbers with given avarage

by ChOas (Curate)
on Mar 12, 2002 at 12:21 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151095]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found