Date: Mar 1, 2013 9:31 AM
Author: Luis A. Afonso
Subject: PI on duty to check a PRNG
PI on duty to check a PRNG

Suppose we are estimate by a random simulation / Monte Carlo procedure pi=3.14159? . The Probability to have at most a difference relative to the true pi value is given by the DKW formula:

en.wikipedia.org/wiki/Dvoretzky-Kiefer-Wolfowitz inequality

Table of values x and their probabilities, N=16E06 trials.

___x<3.1412_____p=0.00

___x=3.1412_____p=0.01

_____3.1413_______0.13

_____3.1414_______0.60

_____3.1415_______(1.51)

_____3.1416_______(2.00)

_____3.1417_______(1.39)

____ 3.1418_______0.51

_____3.1419_______0.10

_____3.1420_______0.01

>3.1420__________ 0.00

Therefore we must observe our empirical results inside the interval [3.1412, 3.1420] if the simulations are working properly.

Experience setting:

In the Cartesian plane (orthogonal axis, x, y) let be the square with vertices on (0, 0), (1, 0), (1, 1), (0, 1) and C= (0.5, 0.5) the centre of the circumference (radius= 0.5) tangent to the square sides. When a point W= (randomX, randomY) falls inside the circumference with area pi*0.5*0.5 one has:

_____(x - .5)^2 + (y - .5)^2 <= 0.25,

condition to which a success is counted.

Outputs:

_3.1417 , 3.1416 , 3.1416 , 3.1416 , 3.1417 , 3.1416 ,

_3.1422*, 3.1415 , 3.1416 , 3.1417 , 3.1415 , 3.1414 ,

_3.1417 , 3.1417 , 3.1417

The stared value is anomalous. . . The PRNGĀ“s performance is not as good as it was desired. It should be used only for illustrative or pedagogical, not research, purposes.

Luis A. Afonso

REM "minus"

CLS

PRINT " (x-.5)^2+(y-.5)^2 <= .25 "

PRINT

all = 1.6E+07

FOR rpt = 1 TO 10

inn = 0

COLOR 13

FOR j = 1 TO all

RANDOMIZE TIMER

LOCATE 4, 50: PRINT USING "##########"; all - j

u = (RND - .5) ^ 2 + (RND - .5) ^ 2

IF u <= .5 ^ 2 THEN inn = inn + 1

LOCATE 10 + rpt, 40

PRINT USING "#.#### "; 4 * inn / j

NEXT j

NEXT rpt

END