/* Random Number Distributions Barry Threw Mills College Version 1.0 - 11/30/04 Implemented Distributions: Gaussian LaPlacian Poisson Gamma Chisquare Cauchy Weibull */ +SimpleNumber { gaussian { arg spread = 1; ^(((sqrt(-2.0 * log(1 - 1.0.rand)) * cos(2pi * 1.0.rand)) * spread) + this) } laplacian { arg tau = 1; var a; a = 2.0.rand; if ( a >= 1,{ ^(neg(log(2.0 - a)) * tau + this); },{ ^(log(a) * tau + this); }); } poisson { var a, b, c; a = exp(this.neg); b = 1.0.rand; c = 0; while ({b > a},{ c = c + 1; b = b * 1.0.rand; }); ^c } gamma { arg nu = 1; var a, b; a = 1; nu.do({a = a * (1 - 1.0.rand)}); b = log(a).neg/this; ^b } chisquare { var a, b, c; c = 0; this.do({ a = 1.gaussian; b = a * a; c = c + b; }); ^c } cauchy { arg pos = 0; var a, b; a = 1.0.rand; if ( pos == 0,{ a = a * pi; },{ a = a * (pi/2); }); b = (sin(a)/cos(a)) * this; ^b } weibull { arg s = 1; var a, b; a = 1.0.rand; while ({a == 0},{ a = 1.0.rand; }); b = (log(1.0/a) ** this) * s; ^b } }