You are on page 1of 3

!"#$%&'"() +,(-./'0 1()2",#")3 '4. 56&)7(#).889 (2 & 6&)7(# :$#;., <.).

,&'(,

Novembei 14, 2u1S

Stuuents: Baniel Intskiiveli, uuipieet Singh, anu Sunny uupta


Nost piogiammatic implementations of
ianuom numbei geneiatois call themselves
"pseuuoianuom" because of the inheient
impossibility of geneiating a tiuly ianuom
numbei. Bowevei, an implementation can be
calleu "sufficiently" goou if the numbeis it
geneiates aie unifoim; i.e. any valiu value within
an inteival passeu to a geneiatoi has an equal
piobability of being ietuineu by the function, anu
they aie inuepenuent of each othei. Foi this
exeicise, we chose to test the ianu() function
pioviueu by the NatLab softwaie suite.


!"#$%& () * +",$-. /0&/1 23 40& 5)6)7) $,"8# - 92"8/-%& 9.24)
+(")/&,. +%('

The fiist test we conuucteu, a two-
uimensional Poincaie plot, is as simple as it is
subjective. We useu the ianu() function to
geneiate two vectois of 1uuuu ianuom elements
in the inteival |u,1j. We then plotteu the vectois
against each othei as uistinct uata points. A
unifoimly uistiibuteu ianuom function woulu
iesult in a plot that has an appioximately equal
amount of uata points in any selecteu aieas of the
same size. We can confiim this visually by noting
that theie appeais to be no pattein oi coiielation
in the geneiateu plot. We can also extenu this
obseivation by wiiting a function to count the
numbei of uata points in a numbei of inteivals of
the same size. If the ianu() function weie unifoim,
this function woulu confiim that each sub-aiea of
the plot contains appioximately the same numbei
of points, with a ceitain eiioi. We hypothesize
that this eiioi woulu ueciease as the numbei of
uata points geneiateu was incieaseu. This
hypothesis is baseu on oui iesults in the following
section of this papei.

!.3#.)'8 &)7 ="8'(3,&#8

Foi oui seconu test, we wiote a function
ianuhist(n, uiaw) that geneiates a histogiam of n
values when the testeu inteival (|u,1j) is uiviueu
into 2u segments. It also geneiates a histogiam if
uiaw == tiue. A peifectly unifoim function, when
useu in ianuhist(), woulu piouuce a histogiam in
which all the bais aie exactly as tall as the
expecteu fiequency, which is 12u, oi u.uS. Figuie
2 is the iesult of calling ianuhist(1uuu, tiue). In
othei woius, the histogiam was geneiateu using a
vectoi of ianuom numbeis of size 1uuu. We
subjectively noteu that as we inciease n, theie
appeais to be less eiioi in the histogiam; i.e. the
bais aie all ielatively closei to the expecteu value
u.uS.
But how can we objectively confiim the
ueciease in eiioi as n giows. Bow uo we calculate
a numeiical value foi this subjective "eiioi" value.
We came to the conclusion that the eiioi foi each
segment is the uiffeience between the actual
!"#$%& :) * 0",42#%-; #&8&%-4&< => /-.."8# %-8<0",4?(@@@A 4%$&B
fiequency of ianuom numbeis geneiateu in that
segment anu the expecteu value, u.uS. In oiuei to
aggiegate the eiioi foi the entiie histogiam foi a
specific n, we founu the noim of the eiioi vectoi,
which contains the afoiementioneu uiffeience foi
each of the segments. We also mouifieu oui
ianuhist() function to ietuin this eiioi value.

We then wiote a function that calls
ianuhist(n, false) foi a numbei of "n's" anu plots n
against the eiioi noim geneiateu in oiuei to
check that the eiioi uoes inueeu conveige to u as
n incieases. In figuie S above the uata points of n
vs. eiioi noims aie plotteu in blue. The ieu cuive
is a iegiession cuive fitteu to the uata points. 0ui
coue piints a numbei of "goouness of fit" values to
piove that the fit is inueeu "goou". It also piints
the equation of the cuive, which coulu be useu to
obtain an appioximate eiioi noim value foi a
specific amount n of tiials. Because the geneial fit
mouel has just one vaiiable, one coulu also use
that equation to easily pieuict the numbei n of
tiials iequiieu to fall within a ceitain piecision. In
geneial, as the numbei of tiials incieases, eiioi
uecieases, anu theiefoie piecision incieases. Also,
the iate of conveigence uecieases as n incieases.



>.)8"'? @$)/'"()8 &)7 '4. 1.)',&% A"#"'
B4.(,.#

Accoiuing to the Cential Limit Theoiem,
the mean of a numbei of ianuom obseivations, oi
vaiiables, is not always the same. In auuition, the
theoiem states that the uistiibution of these
means appioaches appioximately "noimal
uistiibution" with the sample of the aveiages of a
laige numbei of ianuom vaiiables. Theiefoie it
follows that, if a ianuom function is tiuly ianuom,
calculating the mean of x tiials y times anu
plotting those means will piouuceu a plot that
takes the appioximate shape of a bell cuive. If the
NatLab ianu() function confoims to the Cential
Limit Theoiem, we coulu concluue that the values
it geneiates aie inuepenuent fiom each othei anu
that the function is a goou appioximation of tiue
"ianuomness".

In oiuei to conuuct this test, we
calculateu the means of 1uu, 4uu, anu 16uu
ianuom numbeis. We uiu this 1uuu times foi each
of these aibitiaiily chosen numbeis, then plotteu
!"#$%& C) * 9.24 23 8A 40& 8$;=&% 23 4%"-.,A +,) 40& &%%2% +&/42% 82%;
/-./$.-4&< => %-8<0",4?8A 3-.,&B) D0& 9.24 -.,2 "8/.$<&, - %&#%&,,"28
."8&A E0"/0 E-, #&8&%-4&< E"402$4 -8> ,;2240"8# 23 40& <-4-)
!"#$%& F) * 9.24 23 (G8 +,) 40& &%%2% +&/42% 82%;) D0", 9.24 ", -
/.&-%&% %&9%&,&84-4"28 23 40& 3-/4 40-4 40& &%%2% -99%2-/0&, @ -,
8 -99%2-/0&, -8 "83"8"4&.> .-%#& +-.$&)
!"#$%& H) D0", 40& <&%"+-4"+& 23 40& 3"44&< ;2<&. "8 3"#$%& C
9.244&< E0&%& > ", "8 - .2#-%"40;"/ ,/-.&) D0", 9.24
/.-%"3"&, 40& 3-/4 40-4 40& -=,2.$4& +-.$& 23 40& %-4& 23
/28+&%#&8/& <&/%&-,&, -, 8 "8/%&-,&,)
the uistiibutions of the means on a single plot. The
giaph seives two puiposes. Fiist of all, each of the
thiee histogiams on the plot has ioughly the
shape of a noimal oi a bell cuive, subjectively
pioving that the ianu() function piouuces
inuepenuent ianuom vaiiables because of its
confoimity to the Cential Limit Theoiem. In
auuition, it is easy to see that the bell cuive is
naiiowei foi highei numbeis of n; i.e. the plot foi
the means of 4uu tiials is naiiowei than the plot
foi 1uu, the 16uu plot is naiiowei than the 4uu
plot. This is fuithei eviuence to suggest that the
eiioi uecieases with highei "n's".








1()/%$8"()

In it's uocumentation, NatLab claims that
the ianu() function "R = RANB(N) ietuins an N-
by-N matiix containing pseuuoianuom values
uiawn fiom the stanuaiu unifoim uistiibution on
the open inteival(u,1)". 0ui tests seive as
subjective confiimations that the values piouuceu
by this function aie inueeu pseuuoianuom in that
they aie inuepenuent fiom each othei, anu that
they aie inueeu unifoimly uistiibuteu. In the
futuie, it woulu be helpful to iun each of these
tests a laige numbei of times to asseit that the
iesults iemain tiue when the function is stiess
testeu. It woulu also be useful to piogiammatically
check the unifoimity in the Poincaie plot, as
ievealing as a simple visual check might be.
!"#$%& I) D0& <",4%"=$4"28, 23 40& 3%&J$&8/"&, 23 40& ;&-8, 9.244&< 28 40& ,-;& #%-90) D0&> -.. 4-1& 40&
-99%2K";-4& ,0-9& 23 - =&.. /$%+&)

You might also like