HPO機密日誌

自己をならふといふは、自己をわするるなり。

正規分布乱数発生プログラム ActiveBasic

[参照]wikipedia:乱数列
http://ja.wikipedia.org/wiki/%E4%B9%B1%E6%95%B0#.E6.AD.A3.E8.A6.8F.E4.B9.B1.E6.95.B0

#console

dim i,j as integer
dim x,y1,y2 as single

'正規分布乱数サブルーチン:引数c1,c2は、一様乱数

function bell_rand(c1,c2) as single

dim d,e as single

d=Sqr(-2 * Log(1-c1)/Log(10))
e=2*3.1415926535897932*c2
bell_rand=d*Cos(e)

't=sqrt(-2.0 * log(1-rnd()));
'u=2*PI*rnd();
'r1=t*cos(u) ; r2=t*sin(u);

end function

Randomize

for i=1 to 100

y1=Rnd()
y2=Rnd()
x=bell_rand(y1,y2)

Print x

next

input x