Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Answer: How do I get random numbers that follow standard distribution?

by lhoward (Vicar)
on Aug 09, 2000 at 00:55 UTC ( #26894=categorized answer: print w/replies, xml ) Need Help??

Q&A > math > How do I get random numbers that follow standard distribution? - Answer contributed by lhoward

How about something like this:
sub f{ my $t=0; $t+=rand() for(1..5); return int($t*20+1); }
You can vary the number of iterations (1..5) and scaling factor (20) based on the exact distribution curve you want.

There are several other ways to approach this problem. If efficiency were of paramount importance, I would try using statistical method to derive a function that would aproximate the curve of how in frequency you would map numbers from 0 to 0.9999 (the range of perl's rand function) into the range you want (1 to 100).

  • Comment on Answer: How do I get random numbers that follow standard distribution?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2020-10-27 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (258 votes). Check out past polls.

    Notices?