Win has asked for the wisdom of the Perl Monks concerning the following question:

Please for one minute imagine a bell shaped (normally distributed) curve with set standard deviations. On the x-axis we have Variable X. The probability of being randomly assigned the Variable X where variable X = b depends on where b is on the x-axis. I would like a Perl program that can randomly pluck out any X variable, with the probability of this plucking being determined by the normal distribution. Can anyone please help me do this?

Replies are listed 'Best First'.
Re: Working with bell shaped curves
by kyle (Abbot) on May 18, 2007 at 14:30 UTC
Re: Working with bell shaped curves
by swampyankee (Parson) on May 18, 2007 at 15:05 UTC

    Also, check out CPAN, e.g. this, or more specifically, this.

    emc

    Insisting on perfect safety is for people who don't have the balls to live in the real world.

    —Mary Shafer, NASA Dryden Flight Research Center
Re: Working with bell shaped curves
by jbullock35 (Hermit) on May 21, 2007 at 00:13 UTC

    It sounds as though you want to take random draws from a Normal distribution. I suspect that it's best to do this by calling R from Perl; that's how I did it. I don't have the code onhand, but I found almost all that I needed to know in the link from the previous sentence. (Also see this comment and Perl & Math: A Quick Reference. The relevant command in R is rnorm().)

    As your needs grow -- e.g., if you start needing to take draws from different distributions, many of which are not written up in Perl modules -- it will help you more to be calling R from Perl.

    Note that the probability of a draw from a continuous (e.g., Normal) distribution assuming any particular value is approximately zero.