That means that each number has the same chance to occur.
In natural processes the distribution curve however has often a bell shape.
That means that the frequency of occurrence of extreme numbers is far lower than the mid-values.
A special bell-shape is the Gaussian distribution curve.
It is also called the normal distribution because it is often a characteristic of the variation in normal natural processes.
In order to simulate natural processes, I developed a Gaussian number generator according to the "Marsaglia polar method".
See http://en.wikipedia.org/wiki/Marsaglia_polar_method
By using the complex random number generator of SB, it was rather easy to do.
The following code is a program in which the distribution curve of that function 'GRAND()' is tested.
Code: Select all
'Gaussian Noise: function GRANDC() with testprogram
'by Dutchman, january 2015
twidth=3 'total width: sigma's
count=1E5 'total of random numbers
mid=12 'mid size of distribution
FontSize=FONT_SIZE()
sh=SCREEN_HEIGHT()
lines=sh/(1.2*fontsize)-5 ' number of lines to print
size=2*mid+1 'array-size
OPTION BASE 0
DIM number(size)
'---- fill array with distribution
PRINT "Calculating:"
sw=SCREEN_WIDTH()
SLIDER "run" VALUE 0 AT 0,30 SIZE sw
FOR i=1 TO count/2 'two numbers per cycle
n=GRANDC()
u=REAL(n) ! i1=mid+INT(mid/twidth*u)
v=IMAG(n) ! i2=mid+INT(mid/twidth*v)
IF i1<size AND i1>0 THEN number(i1)+=1
IF i2<size AND i2>0 THEN number(i2)+=1
IF i%100=0 THEN SLIDER "run" SET VALUE 2*i/count
NEXT i
SLIDER "run" DELETE ! TEXT CLEAR
'---- show distribution
PRINT "Distributioin within total width of";twidth;"sigma"
PRINT "Width (%)","Total (%)"
n=number(mid) ! i=0
repeat:
PRINT "####.#":100*(2*i+1)/size,"####.#":100*n/count
i+=1
IF i<=MIN(mid,lines) THEN
n=n+number(mid+i)+number(mid-i)
GOTO repeat
ENDIF
'---------- peak calculation
peak:
p=200
DO
p-=1
n=10^-p+1i*10^-p
UNTIL ABS(n)^2>1E-300
p-=1
GRANDC.preset=1
GRANDC.n=10^-p+1i*10^-p
GRANDC.s=ABS(GRANDC.n)^2
PRINT
PRINT "Peak=";GRANDC();" at seed: n=";GRANDC.n
END
DEF GRANDC()
'Generates random complex number
'with Gaussian distribution
'according to the Marsaglia polar method
'r'Remove tinted lines: is only for peak testing
IF preset THEN Transform
''Start with random complex number within limits
DO ! n=RNDC(1) ! s=ABS(n)^2
UNTIL s<1 AND s>1E-320
Transform:
m=SQR(-2*LN(s)/s)
u=SIGN(RND(1)-0.5)*REAL(n)*m
v=SIGN(RND(1)-0.5)*IMAG(n)*m
RETURN u+1i*v
END DEF