May 4
高斯分布效果
ActionScript3.0
高斯部分 可以模拟一些无规律的物体运动
public static function random():Number
{
return Math.random();
}
public static function randomPair():Array
{
return [random(), random()];
}
public static function uniform():Number
{
return 2.0 * Math.random() - 1.0;
}
public static function uniformPair():Array
{
return [uniform(), uniform()];
}
public static function gaussian():Number
{
return gaussianPair()[0];
}
public static function gaussianPair():Array
{
var x1:Number, x2:Number, w:Number;
do {
x1 = uniform();
x2 = uniform();
w = x1 * x1 + x2 * x2;
} while (w >= 1.0)
w = Math.sqrt(-2.0 * Math.log(w) / w);
return [x1 * w, x2 * w];
}
最新评论及回复