Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!mips!pacbell.com!ucsd!casbah.acns.nwu.edu!ajburke From: ajburke@casbah.acns.nwu.edu (Austin Burke) Newsgroups: comp.lang.pascal Subject: Re: Random numbers Message-ID: <1991Mar8.031013.14902@casbah.acns.nwu.edu> Date: 8 Mar 91 03:10:13 GMT References: <1991Mar7.193727.1629@tjhsst.vak12ed.edu> Organization: Northwestern University Lines: 50 In article 1624 John Mitchell writes: > How does TP 5.5 generate random numbers? The numbers generated are not really random. Each number is derived from the preceding "random" number by a complex math equation, and then forced (by another formula) to fit into the given range. > We are using this statement: r := random; which returns a >real number in the range [0,1). Does TP use some kind of formula >to generate these values? Or is there an internal list of random >numbers that is accessed? Does "randomize" seed a formula or >find a spot in the list to start from? There is no internal list. The formula used is, approximately, the following: seed = (multiplier * seed) + (incrementor mod modulus) where "seed" is the previous number generated, "multiplier" is some very large constant number, as is "increment," and "modulus" is 65536. The result of this formula is then forced to fit into the range given by the user. The "randomize" command gives TP its first "seed." This first seed is derived (I think) from the current time, measured in hundreths of a second (or even more exact - I'm not sure). Through this process, seemingly random numbers are generated. It is conceivable, but not likely, that the exact same sequence of "random" numbers may be generated if the initial seed is the same. This is why the current time is used - it makes this possiblity all the more unlikely. > My students are writing a program to approximate pi using the >Monte Carlo method. Our problem is that we are experiencing a >relatively wide range of answers for pi (+/- 0.2) which is not >improved by running the program with more iterations. Sorry, I'm not familiar with the Monte Carlo method. >P.S. Does TP generate random integers using the same method? >P.P.S. Would anyone be able to send me a formula for generating >good random numbers that might be substituted for the TP function >call? See above. -- __ _____ ___ ___________________________ / | | |__) Austin J. Burke III /---| | | \ ajburke@casbah.acns.nwu.edu / | \__/ |__/ Northwestern University