Re: ERROR IN AFONSO CODE
- From: Scott Hemphill <hemphill@xxxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 13:58:22 -0400
John Smith <jsmith_100@xxxxxxxxxxx> writes:
Another funny thing about the Afonso code,
since the PRINT statements are inside the v loop, and
v increments from 1 to 40000, there should be 40000 prints. Yet Afonso's output has only a few prints.
Hmmmm..
REM "TWO
CLS
pi = 4 * ATN(1)
nn = 32
all = 40000
vc = 1.96
RANDOMIZE TIMER
FOR v = 1 TO all
sx = 0: sy = 0
FOR j = 1 TO nn
a = SQR(-2 * LOG(RND)): r = RND
x = 100 + 4 * a * COS(2 * pi * r)
y = 100 + 4 * a * SIN(2 * pi * r)
sx = sx + x / nn: sy = sy + y / nn
NEXT j
t = ABS(sx - sy)
IF t <= vc THEN inn = inn + 1
IF t > vc THEN outt = outt + 1
LOCATE 10, 10
PRINT USING "######"; all - v
PRINT USING "##.###"; inn / v
PRINT USING "##.###"; outt / v
RANDOMIZE TIMER
NEXT v : END
Notice the "LOCATE 10, 10" statement in the code. I believe this
causes the next PRINT statement to display at row 10, column 10 on the
screen. So the three PRINT statements do an on-screen update,
replacing the values that were already there.
I'm surprised you didn't say anything about the use of "RANDOMIZE
TIMER" inside the v loop. This initializes the random number
generator using the timer as a seed. The timer has a fixed resolution
(1/100th of a second?) so if the computer is fast enough, the same
random numbers will be generated in more than one pass through the v
loop. Even if the computer is not fast enough, the timer values will
be close to each other and the first random numbers generated on
successive passes will be correlated with each other. Another thing
is that the RANDOMIZE statement in Microsoft BASIC only uses 16 bits
of the seed values, so there are only 65536 possible sets of random
numbers.
The code would be much better off with the "RANDOMIZE TIMER" in the v
loop removed. Then you could get the full benefit(?) of Microsoft's
24-bit linear congruential generator.
Scott
--
Scott Hemphill hemphill@xxxxxxxxxxxxxxxxxx
"This isn't flying. This is falling, with style." -- Buzz Lightyear
.
- Follow-Ups:
- Re: ERROR IN AFONSO CODE
- From: Old Mac User
- Re: ERROR IN AFONSO CODE
- References:
- ERROR IN AFONSO CODE
- From: John Smith
- Re: ERROR IN AFONSO CODE
- From: John Smith
- ERROR IN AFONSO CODE
- Prev by Date: Re: Statistics and the Mystery of the Feet
- Next by Date: Re: ERROR IN AFONSO CODE
- Previous by thread: Re: ERROR IN AFONSO CODE
- Next by thread: Re: ERROR IN AFONSO CODE
- Index(es):
Relevant Pages
|