vendredi 7 août 2015

Random numbers in the shape of a bell curve

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: http://ift.tt/1MRAG9t

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)




Aucun commentaire:

Enregistrer un commentaire