开发者

how to generate an array of number in a skewed normal distribution? [duplicate]

This question already has answers here: 开发者_运维问答 Closed 10 years ago.

Possible Duplicate:

generating random numbers from skewed normal distribution

i expect a long array containing integers [3,7,7,7,7,1....]

but the overall distribution should be skewed and normal.

using random() generates a uniform distribution.....


If you are looking for just a few integers as your random numbers, then divide the range of random numbers accordingly.

For example, if your random function returns a number from zero to 1, and you want "3" to have a frequency of 10%, and "7" a frequency of 40%, you could say something like

uneven_rand()
{

    r = rand();
    if (r < 0.1) return 3; // covers range from 0 to 0.1
    if (r < 0.5) return 7; // Covers range from 0.1 to 0.5
    etc...
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜