Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by lhoward (Vicar)
on Aug 09, 2000 at 00:55 UTC ( [id://26894]=note: print w/replies, xml ) Need Help??


in reply to How do I get random numbers that follow standard distribution?

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 Re: How do I get random numbers that follow standard distribution?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26894]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found