Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Anonymous Monk
on Aug 16, 2000 at 13:22 UTC ( [id://28080]=note: print w/replies, xml ) Need Help??


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

sub norm{ my $v1,$v2,$r; if( defined $v2 ){ $v1 = $v2; undef $v2; }else{ do{ $v1=rand(2)-1; $v2=rand(2)-1; $r = $v1*$v1+$v2*$v2; }while( $r >= 1 || $r == 0 ); $r = sqrt(-2*(log $r)/$r); $v1 *= $r; $v2 *= $r; } return $v1; }
  • Comment on Re: How do I get random numbers that follow standard distribution?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How do I get random numbers that follow standard distribution?
by jimbojones (Friar) on Feb 16, 2005 at 23:01 UTC
    Just to let others know: this method appears to be from "Numerical Recipes in C", which is now available, full-form, online. See c7-2.pdf.

    this also features recipes for other distributions, plus lots of other good stuff ....

    - j

Re: Answer: How do I get random numbers that follow standard distribution?
by Roy Johnson (Monsignor) on Feb 17, 2005 at 15:31 UTC
    This is a buggy translation from Knuth. $v2 will never be defined; it should have been declared outside the sub.

    Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://28080]
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: (3)
As of 2024-04-24 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found