PowerBASIC Forums
  Cafe PowerBASIC
  Pi-in-sky (Page 1)

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone!
This topic is 2 pages long:   1  2 
next newest topic | next oldest topic
Author Topic:   Pi-in-sky
Emil Menzel
Member
posted January 29, 2005 01:06 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
$IF 0
I've got a problem. I don't know whether it is mathematical, theological,
biological, psychological, physical, computational or "all of the above".
But I don't suppose it matters, because this Forum seems open to questions
and discussions in just about any field. Given, however, that virtually
all readers of the PBForum will be programmers, let me state my problem
in terms of a simple BASIC program.

Problem: Is there a bug in my "Pi-in-sky" program, and if so, where does
it lie? Is it a hardware problem or a software problem? Should I not be able
(at least in principle, and if I run the program long enough) to get
an answer that is as accurate as anyone could wish?


Footnote: Some readers infer from A.K. Dewdney that one can literally
determine the mathematical value of Pi from such a program, and Richard
Dawkins would surely concur. But mathematicians are not likely to be
impressed. (And it is worth noting that William Paley was first and
foremost a mathematician). Letting the program run for about ten
seconds on a 1985-vintage PC does indeed give one an estimate of Pi
that is accurate to about 3 decimal places, and running
the program for 24 hours on a 1995-vintage PC might produce
an answer that is accurate to seven decimal places. H'mmm... How
soon can we expect an answer that is accurate to, say, 30 decimal
places? -- using random numbers, that is.

Footnote 2: I am not asking for other, better algorithms for calculating
Pi. They are obviously available, and some have already been used to
compute Pi to more than one billion decimal places. The question is,
what are the bugs or limits in the present algorithm.

$ENDIF

'**** THIS IS FREEWARE ****
'Pi-in-sky.BAS, a.k.a. Climbing Mount Impossible
'by E.W.Menzel, Jr.
'original version written in 1985
'based on:
' A.K. Dewdney, The armchair universe, 1988, p.218. First published
' in Scientific American, Apr 1985 "Computer recreations column"
' W. Press et al, Numerical recipes: The art of scientific
' computing, 1986 -- chapter on random numbers
' P. Beckman, A history of pi, 1971
' R. Dawkins, The blind watchmaker, 1986
' W. Paley, Natural theology, 1828

'Language: PB-DOS (or PBCC for Windows, with one change, as noted)


X=PBMAIN 'use this line for PBDOS; delete it or REm-out for PBCC
FUNCTION PBMAIN
DIM start AS SINGLE 'the type of variable used might affect answer
DIM tickfactor AS EXT
DIM n AS EXT
DIM x AS EXT, y AS EXT, d AS EXT, i AS LONG, j AS LONG
DIM tot AS EXT, one AS EXT,four AS EXT
DIM loopmax AS LONG, accuracy AS LONG
DIM pi AS EXT
DIM pi2 AS STRING, pi0 AS STRING
DIM date1 AS STRING, date2 AS STRING
DIM temp AS STRING, mask AS STRING


pi0$="3.141592653589793238462643383279" 'actual value of Pi
'to 30 decimal places, which is most likely more than needed.

mask$="N ###### est. pi ##.########## Ndigits ok ##"
one=1
four=4
loopmax=1000000 'no. of random nos. per loop
tickfactor= 1## / (1193180## / 65536##) 'sec per clock tic
date1$=DATE$+" "+TIME$ 'starting date & time


start=TIMER 'for use as seed number for random number generator.
'At least on PC's, the same seed number will produce
'exactly the same sequence of pseudo-random numbers, each time
'the program is run... There are only about
'18.2 x 60 x 60 x 24 other outcomes possible using this
'method since the PC's timer ticks 1193180/65536
'per sec and there are of course 60*60*24 sec in a day.
'Thus an exhaustive account -- of a particular machine --
'is possible in principle, if not in fact.

RANDOMIZE start 'start the random number generator w/ a given seed

CLS
LOCATE 14,1
PRINT "Pi-in-sky: Computing Pi by random numbers. "
PRINT "N is number of random numbers used so far -- in millions.
PRINT "Accuracy is no. of digits correct."
PRINT
PRINT "Started ";date1$; " using seed number";start
PRINT
PRINT " N est.Pi accuracy"
DO
'this loop is the core of the program
FOR i=1 TO loopmax
x=RND(1)
y=RND(1)
d= sqr(x*x + y*y)
IF d < one THEN INCR tot
NEXT
n=n+loopmax
pi=four*(tot/n) 'the current estimate
pi2$=STR$(pi) 'convert to string
pi2$=LTRIM$(pi2$) 'get rid of leading spaces
'how accurate are we?... how many decimal digits?
FOR j=1 TO LEN(pi2$)
temp$=MID$(pi0$,1,j)
IF INSTR(pi2$,temp$)=1 THEN
accuracy=j
ELSE
EXIT FOR
END IF
NEXT
accuracy=accuracy-1 'the decimal point doesn't count

IF INSTAT THEN 'if user pressed a key
PRINT 'scroll down 1 line
IF INKEY$=CHR$(27) THEN EXIT DO 'if Esc key, quit
ELSE
LOCATE ,1
END IF
IF LEN(pi2$)<20 THEN pi2$=pi2$+SPACE$(20-LEN(pi2$))
PRINT n/loopmax;SPACE$(5);pi2$;accuracy;
LOOP
date2$=DATE$+" "+TIME$
PRINT
PRINT "stopped ";date2$

DO UNTIL INSTAT: LOOP
END FUNCTION


------------------


[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Emil Menzel
Member
posted January 29, 2005 04:23 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
This is not directly related to my original problem, but
speaking of alternative algorithms, look up "Computing Pi"
on Google. One of the most intriguing "hits" I got was:
http://numbers.computation.free.fr/Constants/PiProgram/pifast.html

It boasts an algorithm that can compute 128 million digits of
Pi in 15 min on a Windows PC. It also claims to have computed
over 25 billion digits -- again on a PC. Wow!


Actually, such a program might provide a way to solve many
problems involving random numbers: for example, see Donald
Darden's recent post. Nobody yet has been able to prove that
the digits of Pi are non-random and of course they are infinite
in number. (I once read that most PC random number generators
are based on Pi, but I do not know whether or that is so.)


------------------

[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Emil Menzel
Member
posted January 29, 2005 04:40 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
The math web site that claims to
know the slowest and most inefficient known algorithm
for computing Pi:
http://www.mathpages.com/home/kmath011.htm

I'll bet that my offering, Pi-in-sky, beats that proud record,
and it won't be hard to test my boast in short order.

------------------

[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Chad D. Wood
Member
posted January 31, 2005 01:08 AM     Click Here to See the Profile for Chad D. Wood     Edit/Delete Message   Reply w/Quote
The problem of pi is the problem of calculus in general. There are some numbers that you cannot put your finger on... because they are not numbers, they are CONCEPTS. You do not express them as a known, but rather as a relationship between to knowns. Pi will flow out to infinite digits because its end is found only in the granularity of the abstract mathematical universe. It has the same number of digits as ".3333333333..."

People want to have a discrete unit, but they can't have it. People don't like infinite things. Calculus festers in the gaps between "atoms." To measure something is not to exactly know it, it is to know it according to a level of generalization you are comfortable with. While you might measure something to a "perfect inch" on a ruler, you do so ignoring that the lines on the ruler have thickness. You can always zoom in a little more, get a little more detail.

------------------

IP: Logged

Emil Menzel
Member
posted January 31, 2005 03:08 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
Chad:

Thank you for your thoughtful reply. You are right, I'm sure,
about Pi itself. But my question was more about the program.
In other words, our prior knowledge about Pi enables us to
use Pi as a tool, or a criterion, for evaluating empirical
programs or even empirically-oriented theories about nature.

To be more precise about what the program does, let me
crib from the book by J.C. Sprott which translates
into BASIC some "Numerical Recipes" for generating random
numbers: The program first draws 2 nos. from a random no. generator.
Then it treats these numbers as coordinates of a point. These
points are inside a boxes of unit dimension in their respective
n-spaces. They may, however, be either inside or outside of a
unit circle or 2-d space. The probability that a point will
fall outside the circle can be calculated theoretically as
Pi/4. If the random number generator is not faulty, the points
will fall within the unit circle this fraction of the time, and
the result should [at least according to the statistical "law
of large numbers"] become increasingly accurate as the number
of points increases.

In point of fact, either the random number generator that I
used is faulty or the law of large numbers is faulty, because
even if I run the Pi-in-sky program on my 1.7 gigahertz Dell
for a year it will get no more accurate than it did after one
hour. One reason is that after a given number of points have
been drawn from the random number generator, the same exact
sequence will be repeated. But there are more reasons than that,
and I am by no means aware of all of them. They undoubtedly
involve both software and hardware, math and non-math. As a
long-timer PB programmer & fan of the forums, I would greatly
appreciate further comments.

Coincidentally, I believe that Pi-in-sky is relevant to the
issues that are being discussed in two ongoing posts on the PB
forums, both initiated by Donald Darden. For example, some
commentators ask at some point for "truly random" rather than
mere "pseudo-random" numbers. Some say (not just to play devil's
advocate) that there is no such thing as the former. If anyone
disagrees, I'd ask them to provide me a random number generator
that I can plug into Pi-in-sky, and get it to render estimates
of Pi that are accurate to (say) 30 decimal places. That's very
tame compared to what a philosopher or a mathematician would
ask for, but it will do for starters.

------------------

IP: Logged

Chad D. Wood
Member
posted January 31, 2005 04:29 PM     Click Here to See the Profile for Chad D. Wood     Edit/Delete Message   Reply w/Quote
You'll be getting as close an approximation to Pi as the length of the mantissa on your randomly selected points facilitates.

If RND doesn't return the precision you want, use it to return a digit, zero through nine, and manually assemble a decimal string which you then convert to DOUBLE for math, or something.

OFF-TOPIC: Yes, I just used "mantissa" in casual conversation. Yes, I've written a real-time 3D rendering engine in ANSI C using bare concepts from my own mind. Yes, I failed public school algebra THREE years in a row. It made me enraged with powerlessness and anger at its futility, and I finished with an "F" below 60 each time. Yes, I think public school consists of a hot pile of dog crap, stuffed down kids throats forcefully, one steamy spoonful at a time. Homeschool your kids, and teach them outside the cookie-cutter mold.

[This message has been edited by Chad D. Wood (edited January 31, 2005).]

IP: Logged

Emil Menzel
Member
posted February 02, 2005 02:21 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
I myself was far from a "straight A" student and also scornful of the so-called "Gentleman's C"
of the 1940's (my era in college) once I came to realize what I was really interested in. Should
one love what one's good at, or vice versa? If any of my grand-children ask me that I'll probably
tell them as soon as possible to ask Grandma, because she is much wiser than I am in figuring out
why they are asking such a question. Maybe, however, I'd just start telling them a a (true) story
such as this one:

If I did not flunk plane geometry in grammar school it was a miracle. All I can remember about
it was having to study Euclid's book (not some latter-day watered-down, kiddy version of it) and
memorize innumerable axioms, postulates, etc. and getting rapped on the knuckles for messing up
their exact wording. One of the few axioms and postulates I can remember was "the shortest distance
between two points is a straight line" -- or was it vice versa? That is absolutely crazy, says I.
Can you walk straight across rivers, through mountains, or through the walls of this classroom to
get to the dining room? Miss Chopin and I argued about that until some of the other kids started
to snicker and one of them told me to quit asking dumb questions and just study The Book. I still
say I was right, assuming we are talking about the "real world" as I if not most people see it,
rather than the so-called Ideal (to some, "really-real") World of some mathematicians and
philosophers. I didn't understand the difference between pure logical assumption and claimed
empirical fact, at that age; and the difference between mathematical proof and empirical proof is
and even tougher cookie. But nevertheless, despite claiming for many years to "hate math,"
especially geometry, I struggled with that axiom for many years, and finally got to speak my
piece very explicitly in a chapter in a book, soon to be published by Cambridge University Press,
about the psychology and biology of spatial cognition. I thought of dedicating the chapter to
my geometry teachers, Miss Chopin and Miss Higgins, but since it was my 50th wedding anniversary
they lost out to my true love, Grandma. Some of the most sobering thoughts I've had about about
this story came when I was reading Albert Einstein's autobiography. For one thing, he did not
think highly of school either. Secondly, he neverthless absolutely loved Euclid's book as a child,
and went so far as to call it "holy". And finally, his discussion of the concepts of distance,
straight lines and so for rang a very loud bell in my head. He was probably a more astute
psychologist when talking about spatial cognition than anybody who has a chapter in the
forthcoming book. The moral of this story is that once you get Grandpa going he doesn't know
when to stop, so are you ready for a break?

Regarding the "other topic," it would really delight fans of William Paley and dismay fans of
Richard Dawkins and natural selection if one could not get an infinitely accurate estimate of Pi
from random numbers unless each of these random numbers is itself, individually, an infinitely
accurate, real number -- not just INT or SNG or DBL or EXT but much, much more precise than that.
I'd go farther than that: if that's right it would be an absolute bombshell in science. I believe
it cannot be right. Maybe you did not imply it. But I still say it's great, and love it.

As it stands, the Pi-in-sky program has yet to come up with an estimate of Pi which come close,
in accuracy, to Pi## = ATN(1) * 4. If it does match the best unaided PB can do, then of course
I will need more accurate numbers. Maybe I should check out my copy of an old, free version
BASIC that deals with 30-place or even higher numbers, or start saving for Mathematica, the
most pricey and powerful math program I've heard of. In the meantime, I have certainly learned of
more potential bugs in my version of Pi-in-sky than I knew of a week ago, thanks to the ongoing
debates in the PB forum on how to test one's random number generator and even more so to your
comments. I thank you.

------------------

IP: Logged

Donald Darden
Member
posted February 02, 2005 04:01 PM     Click Here to See the Profile for Donald Darden     Edit/Delete Message   Reply w/Quote
I'm satisfied at this point that the random number generator is
fairly good and that the cycle is rather long. But since it is
relying on certain fixed values in this determinations, the
cycle is limited. One approach that has been proposed is to
cause the computation to extend over more generations of R[],
such as:

"R[n]=(a * R[n-1) + b * R[n-2] + c * R[n-3] + d * R[n-4]) MOD m"
where a, b, c, and d are all primes, and n refers to the current
iteration in finding subsequent values of R.

I think that just rotating through a series of values for "a"
would give you the same effect, in which case you could simplify
this to read:

"R[n]=(a(x) * R[n-1] + R[n-2] + R[n-3] + R[n-4]) MOD m", which
would make it much faster to perform as well.

And of course I have mentioned that you could modify "a" by
using shifts and possibly other operations, which could include
OR, XOR, bit reversals, and so on. You can even include a few
logical determinations that could change which calculation
method to use in getting a new value for R[n].

It sounds like you test would be a good test of a new algorythm
for calculating a Random Number Generator, if you don't mind
letting the process run on your machine for a year or two.

------------------
Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

IP: Logged

Emil Menzel
Member
posted February 04, 2005 01:21 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
Donald:
Thank you! I am going to study closely the whole series of
comments in the threads you started -- which I found most
interesting. They were the immediate stimulus for getting me
to think more about Pi and statistical sampling and the limits
of simulations, and so forth.

The rest of this post was written before I discovered your
comment. As a program it is little different from my original
one; but is vastly better from a statistical point of view. Any
other random number generator could, of course, be substituted
for the RND function, and any other data for analyzing the
raw X,Y pairs could be substituted for Pi, sumX, etc.

Emil

US army, for 2 years, 50+ years ago. Pvt most of the time, but
I did make Sgt shortly before leaving Korea, and just before
the truce was declared. North Korea is (or was then) one of
the most beautiful places I'd seen, quite possibly because I
was born & raised in India & went to school in the Himalayan
foothills myself. I add that, as soldiers, the North Korean &
Chinese soldiers had, and still have, my highest respect. Isn't
it odd that fighting or dying for one's country is considered
heroic only if it is done by "our" rules? I propose that only
75-yr-olds and above should serve on the front lines;
let our children & grand-children live instead. Gung ho!
Sign me up.

end of note to Donald...


'RNDCHK.BAS
'by Emil Menzel
'Language: PBCC -- PowerBASIC
'FREEWARE
'NOTES:
'1. PBCC's RND function generates fairly high-precision numbers that range between 0 to 1 and
' are uniformly distributed across this range. The exact theoretical expected values of
' these numbers, and their standard deviation, etc. is not hard to compute.
'2. RND's "period" or "length of cycle" is 4,294,967,296, at least on my machine.
' In other words, after that it starts to repeat exactly the same sequence.
' It is not necessary to reset the random number generator any more often than that.
' But remember that 2 RND numbers are drawn from the RND generator for each X,Y point.
' So don't go over 2 billion in variable MaxJ. If "recur(X1-X2)" >0, the odds are that you
' have hit RND's "period".
'2. If you know the seed no. for RANDOMIZE, you can reproduce, exactly, any given sequence of RND's
' and hence the exact same pairs of X,Y values and the exact same estimate of Pi, etc. etc.
'3. The data are printed to file so that you can quit whenever you choose yet still resume later.
'4. You'll see from the data that even with repeated samples of a billion RND's, the mean of each
' sample is never really very close to the exact theoretical expected value -- unless accuracy
' to 5 or 6 places is all you'd ever ask for. If you draw the exact same X,Y pair of RND's
' twice -- and the odds are you will not -- be very suspicious that the random number generator
' is rigged, or see note 2 above.
'5. The print-outs for "Pi" should be exact integer values. (Divide them by 4 to get the original
' exact count of how many time Dist or SQR(X*X + Y*Y) was < 1.)
'6. How close, then, can you come to the exact value of Pi, using a random number generator? No
' closer, I would think, than you get to the value of exactly 0.5 for the mean of X or Y.
'7. The bottom line is that if I had not only done my homework but understood what my teachers
' were saying I'd have known all of the above before I ever got started, and saved months
' of slow, gradual trial-and-error learning. The best 4 pages of advice I have ever seen
' is Steve Skiena's chapter on random number generation, in his book "The algorithm design
' manual"; see also www.cs.sunysb.edu/~algorith/ which Skiena claims is the best single
' web source for high-quality algorithm implementations. His chapter on very-high precision
' arithmetic also has excellent advice. Among other things, it tells of a program that
' would do all such math that I'd need to do and is 100 times faster than Mathematica and
' is free, to boot. Skiena was, coincidentally, an assistant professor at Stony Brook
' about the time I was ready to retire from there; on one occasion we met for about
' an hour. I asked his advice on a program I was working on for solving any given maze or
' detour problem. His tip ("Try, first of all, a breadth-first search, and forget genetic
' algorithms") was dynamite. In his terms, as well as mine, this was a simple "shortest path"
' problem. His own first tip on random number generation, in his book, is that: "generating
' random numbers is a task that looks a lot easier than it is, primarily because it is
' fundamentally impossible to produce truly random numbers on any deterministic device. Von
' Neumann said it best: 'Anyone who considers arithmetical methods of producing random numbers
' is, of course, in a state of sin'...Bottom line: This is an area where people shouldn't
' mess around, but they do." He does go on to tell you how to mess around anyway, I add.
'8. The data that are printed may, of course, be pooled and analyzed further, statistically.
' Skiena recommends vol. 2 of Donald Knuth's classical series on "The art of computer
' programming". Any introductory statistics text will, however, be useful -- especially if
' it discusses the "law of large numbers".
'9. If you do not wonder whether or not this means that the universe or your dog or you
' yourself might be less a "deterministic device" than some self-professed gurus claim,
' that is your problem and none of my own, I suppose. If you are a computer buff, however,
' or maybe even if you are not, you might enjoy Donald Knuth's book on "What computer
' scientists seldom talk about". He's an ardent Bible scholar as well perhaps the dean of
' modern computer gurus. I am a rank amateur in both fields. Most likely, I'll pass my
' original question over to experts in non-computer-science fields. Thanks, PB forum.
'


FUNCTION PBMAIN
DIM X AS EXT, Y AS EXT, Dist AS EXT, firstX AS EXT, firstY AS EXT
DIM recur AS QUAD, Pi AS QUAD
DIM I AS QUAD, J AS QUAD, maxJ AS QUAD,d AS STRING, ffn AS STRING
DIM k AS QUAD, ff AS QUAD

ff=FREEFILE
ffn$="C:\RNDCHK.DAT" 'write to a file that will be easy to find
maxJ=1000000000


IF DIR$(ffn$)<> "" THEN
'find last seed number used for RANDOMIZE... Best keep them sequential!
OPEN ffn$ FOR INPUT AS #ff
WHILE NOT EOF(ff)
LINE INPUT #ff, d$
I=VAL(d$) 'find the last seed number used.
WEND
CLOSE #ff
END IF
OPEN ffn$ FOR APPEND AS #ff
IF I=0 THEN PRINT #ff, d$

PRINT "RNDCHK prints each time it gets ";MaxJ; "data points"
PRINT "The data will be saved to file ";ffn$
PRINT "NOTE: If you know the seed no. for RANDOMIZE, you can reproduce exactly
PRINT " any given sequence of RND's that was used, and everything else too."
PRINT " So you should avoid using the same seed number twice, ordinarily."
PRINT "Exact theoretical expected values for sumX and sumY are 0.5 times N, precisely"
PRINT "Pi(est) should be an exact integer number; if not, it is error"
PRINT "N for a given sample = number of digits in Pi(est), minus one"
PRINT " check Google.com "Computing Pi" for expected values up to many decimal places"

PRINT
PRINT "To quit, press Ctrl+break"
PRINT
d$= "'Seed#, Pi(est), N, sumX, sumX2, sumY, sumY2 sumXY, Recur(x1/y1)" 'data header

PRINT d$ 'data header

DO
INCR I
RANDOMIZE I
'reset counters
Pi=0&&: recur=0: REDIM sum(-2 TO 6)AS EXT
FOR J=1 TO maxJ
X=RND
Y=RND
Dist = SQR(X*X + Y*Y) 'Pythagorean theorem
IF Dist< 1## THEN INCR Pi
sum(1)=sum(1)+ X
sum(2)=sum(2)+ X*X
sum(3)=sum(3)+ Y
sum(4)=sum(4)+ Y*Y
sum(5)=sum(5)+ X*Y

IF J = 1&& THEN
firstX=X: firstY=Y
'note that this checks recurrence of ONLY the first X,Y pair
ELSE
IF X=firstX AND Y=firstY THEN INCR recur
END IF
NEXT
sum(-2)= I
sum(-1)= Pi * 4&&
sum(0)= MaxJ
sum(6)= recur
FOR k=-2 TO 6: PRINT sum(k);: NEXT: PRINT

FOR k=-2 TO 6
PRINT #ff, sum(k);
IF k<6 THEN PRINT #ff, ",";
NEXT
PRINT #ff, ""
LOOP
CLOSE #ff
LINE INPUT d$
END FUNCTION



------------------


[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Emil Menzel
Member
posted February 04, 2005 01:30 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote

error
------------------


[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Emil Menzel
Member
posted February 04, 2005 03:11 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
Another screw-up, or "erratum" as we say in the .edu biz.

------------------

[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged

Emil Menzel
Member
posted February 04, 2005 03:14 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
Hey! If I keep going like this, maybe PB forum will call this
a "hot topic".

------------------

IP: Logged

Eddy Van Esch
Member
posted February 04, 2005 03:22 PM     Click Here to See the Profile for Eddy Van Esch     Edit/Delete Message   Reply w/Quote
Emil,

Small suggestion:
Put your program code inside "[ c o d e ]" and "[ / c o d e ]" (without the spaces) and your code will be much more readable, like this:


a = 10
for i = 1 to a
print i
next i

Kind regards

------------------
Eddy
email: raimundo4u at yahoo dot com
www.devotechs.com -- HIME Huge Integer Math and Encryption library--

IP: Logged

Donald Darden
Member
posted February 04, 2005 06:36 PM     Click Here to See the Profile for Donald Darden     Edit/Delete Message   Reply w/Quote
A truly numeric process for generating a random number sequence
is predetermined to obtain certain results throughout its cycle.

I can only project that a process that includes additional elements.
such as register shifts and logical operators, such as OR and XOR,
and possibly some IF statements, is also predetermined in nature,
but if we do not have a means of expressing how it works, then how
can we determine beforehand what results it will obtain?

To put it another way, if we were to picture a pool table with
balls arranged a certain way, and the pool shooter was poised to
take a shot, we can project what we think the outcome of that shot
might be. But if we were to picture a pool table after the shot,
we don't have a clue 1 as to what the last shot was. Some
information is no longer present to guide us. As we look at a
random process that contains a mixture of elements other than
simple arithmetic, then the number of possibilities increases,
and at the same time some information will be lost going forward,
so that we can not project the past. In terms of going forward,
we can tell what will come if we know all the factors involved,
but we whould have to carry out each stage in order to know what
the next stage will be.

A big factor is not only the seed value, but whether any other
variables are used in our computations. The more variables used
that truly vary, the less certain or predictable the outcome.

In the expression "R[n]=(a * R[n-1] + p) MOD m", what if you
replaced "p" with "TIMER * 100"? Then the very millisecond
that you requested a new RND number, the result would vary. And
since we don't necessarily know when you would make that request,
we can'b be sure of what value you will have.

Of course as long as we are only using the higher order of bits
of R[n], any millisecond changes will take a while in order to
make any real impact. If we were converting R[n] to an integer
and then extracting the lower bits through a MOD, then the
changes would be immediate and significant.

Note that I am not arguing against the concept of trying to
generate a random number generator arithmetically on a
deterministic machine (computer), I'm just showing various ways
in which a deterministic machine can be influenced on the fly to
produce unpredictable results that may or may not appear to be
sufficiently random for use in games and such.

------------------
Old Navy Chief, Systems Engineer, Systems Analyst, now semi-retired

IP: Logged

Emil Menzel
Member
posted February 04, 2005 10:56 PM     Click Here to See the Profile for Emil Menzel     Edit/Delete Message   Reply w/Quote
Eddy:
Will try to remember that tip on formatting -- my method makes
EDLIN (the predecessor of Notepad) look like a world-class
word processor. Will also check out your website on high-
precision libraries, too.

Donald:
Isn't that the formula that is used for many roulette wheels?
If so, it's approximation to pure chance is certainly good
enough to fool 99.9 people out a thousand, including this
non-gambler and non-physicist. For that matter, if I did not
know either the formula or the seed number and tried to deduce
them from, say, 100 or even 1000 spins of the wheel,
the roulette master would probably smile and welcome me to place
my bets. On the other hand, if I looked like an MIT student and
carried a computer,he might of course call a bouncer.

It has always amazed me that Newton could deduce the motions
of the planets as he did and that his laws enable one to predict
so far ahead, as if the entire universe were literally as
deterministic as a clock. The data available to him were
miniscule by today's standards. Could he have discovered the
pattern if he had a thousand times as much data and a modern
computer? Maybe. But I doubt that I or many others could
have done so. Too much data can certainly be worse than too
little.

Any physical system seems to have some indeterminism if you
look at it more microscopically -- or, sometimes, more
macroscopically -- than Newton's relatively everyday or common-
sensical level of observation. Pool balls are certainly a case
in point, especially if the table surface is not very smooth,
the player is not highly skilled, etc. The best-designed
computer pool games were probably designed by physicists or
those who know classical Newtonian physics very well. Predicting
the ocean tides requires not only physics also some geography
and other disciplines. When it comes to clouds, rain & lightning,
we are still in Newton's ball park but my grandmother's ouija
board and concern for her rheumatism did about as well as
weathermen until fairly recently. The problem is that there
are so many variables operating and so much data is needed to
accurately predict far ahead that the time, effort & cost of
the data collection & analysis would be prohibitive. I have
lived in hurricane & tornado country for many years, and
I often think that we might be better off without so much
public concern about what might happen.

Is apparent indeterminism (especially the apparent indeterminsim
of animal and human behavior) fundamental or only the
result of our ignorance? I do not know. As an ex-scientist I
would most often attribute it to our ignorance, and try to
learn more. But that's more like an "axiom" or an assumed
working principle, not a statement of fact or of dogma. When it
comes to everyday advice, I lean more toward Mark Twain than
"Psychology Today". Or as my father-in-law used to say, when we
were playing cards: "Is this a game of chance? Not the way I
play it". He was the first actuary in Birmingham (the real
Birmingham, in Alabama USA, that is) and that was his favorite
line in a W.C. Fields movie.

I will try different random number generators, for sure. There
are people working on simulations whose work I plan to check
out as soon as possible.

There are disadvantages to the pseudo-random data one gets
from RND & your formula, but there are also very big advantages.
Given the seed number for RND, you can reproduce every single
data point again, on whim, and use any form of analysis you
choose on a suspicious (or interesting) looking sequence of
a billion or more numbers. If you link to TIMER and record the
time, that is of course knowing the seed number -- as long as
you save what the counters say that are converted into time-in-
sec. If I were you, I would by all means save that datum. In
fact you could flaunt the clock's value for all to see, and
who but you would know what that really signifies? (That might
already be used as a signal in some gambling halls.)

Is generating reasonable random sequences easier than
detecting cheaters or vice versa? I'm not sure. It's a cat-and-
mouse game. But I wonder if studies of how to catch plagiarism
(e.g., in literature or in school term papers) might not
be pertinent. See http://turnitin.com/static/home.html. There
used to be people who were really getting hot on that. But of
course someone sued them for invasion of privacy or whatever.
You can't win, can you?

------------------

[This message has been edited by Emil Menzel (edited February 21, 2005).]

IP: Logged


This topic is 2 pages long:   1  2 

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2007 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c