in reply to Curved Random Distribution

Like this?

#! perl -slw use strict; sub binomialRand{ my( $target, $variance ) = @_; return $target + rand( $variance ) + rand( $variance ) - $variance + +0.5; } our $PRECISION ||= 1; our $ITERS = 1000 * $PRECISION; my %plot; $plot{ int( $PRECISION * binomialRand( 100, 5 ) ) / $PRECISION }++ for + 1 .. $ITERS; print "Rand 100 +-5"; printf "%7.2f : %-3d : %s\n", $_, $plot{ $_ }, '#' x ( $plot{ $_ } / $ITERS * 100 * $PRECISION ) for sort{ $a <=> $b } keys %plot; __END__ P:\test>501053 -PRECISION=1 Rand 100 +-5 95.00 : 20 : ## 96.00 : 50 : ##### 97.00 : 99 : ######### 98.00 : 157 : ############### 99.00 : 175 : ################# 100.00 : 167 : ################ 101.00 : 154 : ############### 102.00 : 98 : ######### 103.00 : 53 : ##### 104.00 : 27 : ## P:\test>501053 -PRECISION=10 Rand 100 +-5 95.00 : 1 : 95.10 : 7 : 95.20 : 11 : # 95.30 : 12 : # 95.40 : 12 : # 95.50 : 23 : ## 95.60 : 19 : # 95.70 : 34 : ### 95.80 : 31 : ### 95.90 : 50 : ##### 96.00 : 38 : ### 96.10 : 35 : ### 96.20 : 63 : ###### 96.30 : 62 : ###### 96.40 : 61 : ###### 96.50 : 70 : ####### 96.60 : 65 : ###### 96.70 : 70 : ####### 96.80 : 79 : ####### 96.90 : 83 : ######## 97.00 : 83 : ######## 97.10 : 78 : ####### 97.20 : 89 : ######## 97.30 : 86 : ######## 97.40 : 95 : ######### 97.50 : 102 : ########## 97.60 : 104 : ########## 97.70 : 107 : ########## 97.80 : 108 : ########## 97.90 : 131 : ############# 98.00 : 124 : ############ 98.10 : 120 : ############ 98.20 : 127 : ############ 98.30 : 134 : ############# 98.40 : 136 : ############# 98.50 : 149 : ############## 98.60 : 147 : ############## 98.70 : 134 : ############# 98.80 : 171 : ################# 98.90 : 171 : ################# 99.00 : 157 : ############### 99.10 : 179 : ################# 99.20 : 167 : ################ 99.30 : 196 : ################### 99.40 : 173 : ################# 99.50 : 206 : #################### 99.60 : 183 : ################## 99.70 : 216 : ##################### 99.80 : 175 : ################# 99.90 : 186 : ################## 100.00 : 195 : ################### 100.10 : 211 : ##################### 100.20 : 204 : #################### 100.30 : 186 : ################## 100.40 : 188 : ################## 100.50 : 154 : ############### 100.60 : 192 : ################### 100.70 : 171 : ################# 100.80 : 164 : ################ 100.90 : 157 : ############### 101.00 : 157 : ############### 101.10 : 135 : ############# 101.20 : 147 : ############## 101.30 : 159 : ############### 101.40 : 153 : ############### 101.50 : 135 : ############# 101.60 : 136 : ############# 101.70 : 126 : ############ 101.80 : 121 : ############ 101.90 : 111 : ########### 102.00 : 106 : ########## 102.10 : 114 : ########### 102.20 : 110 : ########## 102.30 : 95 : ######### 102.40 : 99 : ######### 102.50 : 102 : ########## 102.60 : 83 : ######## 102.70 : 72 : ####### 102.80 : 83 : ######## 102.90 : 83 : ######## 103.00 : 68 : ###### 103.10 : 80 : ######## 103.20 : 61 : ###### 103.30 : 68 : ###### 103.40 : 50 : ##### 103.50 : 45 : #### 103.60 : 79 : ####### 103.70 : 56 : ##### 103.80 : 42 : #### 103.90 : 48 : #### 104.00 : 35 : ### 104.10 : 36 : ### 104.20 : 29 : ## 104.30 : 17 : # 104.40 : 21 : ## 104.50 : 24 : ## 104.60 : 15 : # 104.70 : 11 : # 104.80 : 4 : 104.90 : 2 :

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Curved Random Distribution
by Roy Johnson (Monsignor) on Oct 18, 2005 at 17:45 UTC
    Technically, that would be peak-shaped rather than bell-shaped. That is characteristic of probability curves generated with 2 random inputs. Consider the probability table for 2 6-sided dice, for example.

    The higher the number of random inputs, the more the resulting distribution looks like a bell curve.

    Update: Yep, I glossed right over the mention of "triangle"; all I saw was bell and curve.


    Caution: Contents may have been coded under pressure.

      True, but the OP did mention a "triangular" distribution. For a better approximation of a bell curve he might use this:

      sub bRand { my( $target, $variance ) = @_; my $v = sum map rand() * $variance, 1 .. 4; return $target - $variance + ( $v / 2 ); }

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.