def randomn
size = self.size
case type = self.typecode
when COMPLEX; type=FLOAT
when SCOMPLEX; type=SFLOAT
when FLOAT
when SFLOAT
else
raise TypeError, "NArray type must be (S)FLOAT or (S)COMPLEX."
end
rr = NArray.new(type,size)
xx = NArray.new(type,size)
i = 0
while i < size
n = size-i
m = ((n+Math::sqrt(n))*1.27).to_i
x = NArray.new(type,m).random!(1) * 2 - 1
y = NArray.new(type,m).random!(1) * 2 - 1
r = x**2 + y**2
idx = (r<1).where
idx = idx[0...n] if idx.size > n
if idx.size>0
rr[i] = r[idx]
xx[i] = x[idx]
i += idx.size
end
end
rr = ( xx * NMath::sqrt( -2 * NMath::log(rr) / rr ) )
rr.reshape!(*self.shape) if self.rank > 1
rr = rr.to_type(self.typecode) if type!=self.typecode
if RUBY_VERSION < "1.8.0"
self.type.refer(rr)
else
self.class.refer(rr)
end
end