Graphical representation of pseudorandom sequences

Graphical representation of pseudorandom sequences

Comput & Grapkttcs Vol. 13. No. 2. pp. 261-262. 108~ Pnnted in Great Britain. 0097-8493/89 $3.00 ~- .00 © 1989 M~L,v,ell Pergamon Macmillan pie Chao...

131KB Sizes 1 Downloads 163 Views

Comput & Grapkttcs Vol. 13. No. 2. pp. 261-262. 108~ Pnnted in Great Britain.

0097-8493/89 $3.00 ~- .00 © 1989 M~L,v,ell Pergamon Macmillan pie

Chaos and Graphics GRAPHICAL REPRESENTATION OF PSEUDORANDOM SEQUENCES T. RICHARDS IMI Systems Inc., 1 Gatehall Drive. Parsippany, NJ 07054 Abstract--This note describesa simpleapplicationof a chaos-analysistechniqueto expose the non-randomness of the BASIC random number generator. Other potential applications for this technique are also mentioned.

PLO'VrING SUCCESSIVE VALUES OF A SEQUENCE

The technique reviewed in this note provides a simple way of producing two-dimensional graphics from onedimensional data and also for revealing subtle patterns in noisy data. Since the method is very easy to implement on a personal computer, the goal of this note is to encourage students and teachers to explore this technique in the classroom setting. The method plots the Nth data value versus the N + l value, and then the N + 1 value versus the N + 2. For example, if the first three values of a series were 0.9, 0.7 and 0.I then the points plotted would be (0.9, 0.7) and (0.7, 0.1). Obviously this technique can be expanded to produce graphics of higher dimensions. For further background on this technique see [!, 2 ]. For background on more traditional methods used for the detection of randomness and for various methods of random number generation, see [ 3 ]. THE BASIC RANDOM NUMBER GENERATOR I have found surprising results when this approach is applied to the BASIC [4] random number generator. The method is effective in showing that random number generators prior to release 3.0 of BASIC have subtle problems. The non-randomness is not easy to detect using many conventional techniques. Fig. 1 shows the implementation in BASIC. Note the following: 1) the scaling factors in lines 50 and 70 can be changed to enlarge a part of the graphic. The current factors print all values on the screen. 2) The limit checks in lines 60 and 80 are to prevent the program from printing off the edges of the screen. They function as a performance improvement as the PSET function will detect the off-screen condition and return normally. 3) For those readers unfamiliar with BASIC, the PSET function draws a point at the specified coordinates. The other statements should be intuitive. Fig. 2 shows a portion of the generated screen image. This figure is the top left corner of the screen from point (0, 0) to approximately (0.2, 0.5), and the rest of the screen is substantially the same. As can be seen, there is a definite pattern produced which shows that the sequence is not truly random. The complete pattern takes more than 67,000 passes to complete but can be

seen emerging after only a few hundred passes. The data points are represented by + signs. It is possible that the pattern is produced by some artifact of the program logic. The following measures were taken to try to identify any program generated patterns: l ) Various precisions were used for the program variables. 2) Various rounding techniques were tried when the coordinates were calculated. 3) "Slow Down" loops were inserted at various points to eliminate any possible system clock interaction. 4) Similar patterns can be produced by taking various combinations of the values, e.g., plotting every third value. In fact, once this pattern is found, it is almost impossible to destroy it. This suggests that the pattern is a fundamental property of the sequence and not a program artifact. None of these changes altered the fundamental pattern. However, running the same program under release 3.0 of BASIC, which has the improved random number generator, produced a "snow-storm" screen with no discernible pattern. Variations on this technique could be used to examine any sequence of values that appears to be random. If a pattern emerges, the underlying cause may then be investigated. This could have value in applications such as manufacturing tolerances in mass production environments, and transmission noise in communications lines.

10 S C R E E N 2

11 CLS 20 Y = R N D 30X=Y 40 Y = R N D 50 YP = Y . 1 9 9 60 IF YP > 199 G O T O 30 70 X P = X * 639 80 IF XP > 639 G O T O 30 90 PSET ( X P , Y P ) 100 G O T O 30

Fig. 1. Sample BASIC program.

261

262

**.

,

T. RICHARDS

••

•*•



**•

•~•



•6

•°

*





•*•••

. . . . . . . . . . . . . . . . . . . . . .

**•

*••

• i..i"i

*°0

•*••°

*•

*

**

°

•*•

*

°

*°•

***

*•

•**

*.*°

°•



••°°°

•°•

•~0

••

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Fig. 2. Part of the screen output.

REFERENCES 1. J. Gleick, Chaos." The Making of a New Science, Viking, New York (1987). 2. K. Mckean, The orderly pursuit of disorder. Discover, January, 72-81 (1987).

3. G. Gordon, System Simulation, Prentice-Hall, Englewood Cliffs, NJ (1978). 4. The IBM Personal Computer Basic. Version A2. I0. This is an interpreted BASIC.