Sometimes it is necessary to use non-uniform distributed random numbers. One particular case are Gauss-distributed random numbers, i.e. when 'collected', they form the well-known bell curve.
A fairly known trick to produce these is to add up 12 random numbers with uniform distribution between 0 and 1, and subtract 6. This gives random numbers with a mean of 0 and a standard deviation of 1, and whose distribution for all practical purposes is indistinguishable from Gaussian randoms.
Well, let's see how this works out in MINIGRAFIK.
The formula to stretch the range of z = -6 .. +6 to the x-coordinates 0.5 .. 159.5 (+.5 to account for the rounding into 160 'classes') would be X=159*(Z+6)/12+.5, the program below (download) omits the subtraction of 6 in the RNG-formula just to add it again for the scaling:
Code: Select all
1 Q=RND(-TI):CLR:DIMY(159):FORX=0TO159:Y(X)=192:NEXT:@ON:@CLR
2 Z=RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)+RND(1)
3 X=159*Z/12+.5:IFY(X)>0THENY(X)=Y(X)-1:@1,X,Y(X):GOTO2
4 GETA$:IFA$=""THEN4
5 @RETURN