'===========================================================================
' Subject: Analysis of RND Generator          Date: 06-14-02 (  :  )       
'  Author: Michael Webster                    Code: Qbasic, QB, PDS, PB    
'  Origin: mfwebster@pdq.net                Packet: ALGOR.ABC
'===========================================================================
'--------------------------------------------------------------------------------
'Michael Webster
' mfwebster@pdq.net
'--------------------------------------------------------------------------------
' This program does a quick statistical test 
' of the QB pseudo-random number generator. 
' For a set of TRUE random numbers between 
' zero and one, the mean should be 0.5 and 
' the standard deviation should be the 
' reciprocal of the square root of 12. 
' 
' This was adapted from Alan R. Miller's book 
' BASIC Programs For Scientists And Engineers, 
' SYBEX, 1981. ISBN 089588-073-3. 
 
' Use the maximum number of elements possible. 
n% = 16384 
DIM x(1 TO n%) 
PRINT 
FOR i% = 1 TO 10 
    sumx = 0 
    sumsqx = 0 
    FOR j% = 1 TO n% 
        'RANDOMIZE TIMER 
        x(j%) = RND 
        sumx = sumx + x(j%) 
        sumsqx = sumsqx + x(j%) * x(j%) 
    NEXT 
    mean = sumx / n% 
    std = SQR((sumsqx - sumx * sumx / n%) / (n% - 1)) 
    PRINT mean, std 
    meanTotal = meanTotal + mean 
    stdTotal = stdTotal + std 
NEXT 
PRINT "-------------------------" 
PRINT meanTotal / 10, stdTotal / 10 
COLOR 3, 0 
PRINT " .5000000     "; 1 / SQR(12) 
COLOR 7, 0 
 
 
 
