mardi 3 septembre 2019

How to generate random positive floating point numbers with normal distribution from 0 up to a given ceiling?

I need to generate a number of float numbers with normal distribution over a range from 0 to a specific ceiling.

I've searched on stack overflow and found similar questions for other languages, but none for .net core.

internal List<float> function(int ceiling, int repetitions)
{
    List<float> list = new List<float>();
    for (int i = 0; i<= repetitions;i++)
    {
         list.Add(Random.nextFloat() * ceiling);
    }
    return list;
}

I expect the function to return a list of random positive floatnumbers, in range from 0 to a given ceiling with at least approximately normal distribution.




Aucun commentaire:

Enregistrer un commentaire