3

I need to manipulate random to produce a statistical average with the shape of a bell curve, here is my attempt:

Function slopedrand(max As Single, bias As Single) As Integer
    Dim count As Single = 0
    While count < bias
        max = rand.NextDouble() * max
        count += rand.NextDouble()
    End While
    Return rand.NextDouble() * max
End Function

Function bulgedrand(min As Single, max As Single, bulge As Single, bias As Single)
    Dim negative = bulge - min
    Dim positive = max - bulge

    Dim nr = min + slopedrand(negative, bias)
    Dim pr = max - slopedrand(positive, bias)

    Return rand.NextDouble() * (pr - nr) + nr
End Function

however, given that I suck at math, all it produces is stuff like this: https://i.stack.imgur.com/4YTba.png

which is more like a bulge...

Since it feels like my skull is boiling, maybe somebody here has figured out how to accomplish what I need and will spare me from further attempts of thinking?

(the example is given in vb.net since it was quick to prototype on but any language is welcome)

user81993
  • 6,167
  • 6
  • 32
  • 64

2 Answers2

2

The "established" way of doing this is to draw a uniformly distributed random number in the range [0, 1), then apply the quantile function of the Bell curve distribution. This then gives you a random number that has the same distribution as the Bell curve.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
0

A bell curve can be approximated by a normal distribution, so I guess you can use random values inside the formula for a normal distribution and get the effect you need, such as in this answer:

drawing random number from a standard normal distribution using the standard rand() functions

Maybe it can help you?

Community
  • 1
  • 1
Bruno Oliveira
  • 735
  • 10
  • 20