Randomness
From Maze
(Difference between revisions)
| Line 105: | Line 105: | ||
== The Commodore 64's RND Function == | == The Commodore 64's RND Function == | ||
| − | The way that 10 PRINT invokes the randomness provided by the Commodore 64 is of interest for a few reasons which will each be explored in turn. First, using randomness is aesthetically necessary in this program; there is no other way to achieve a similar effect. Second, the methods used in Commodore 64 BASIC are historically quite typical of computational approaches to pseudo-randomness since the 1950s. Finally, out of several common approaches to randomness available on the Commodore 64, 10 PRINT uses a very standard method that is well-suited to experimentation, debugging, and the production of canonical results, although this method is not without its deficiencies. | + | The way that 10 PRINT invokes the randomness provided by the Commodore 64 is of interest for reasons that will each be explored in turn. First, using randomness is aesthetically necessary in this program; there is no other way to achieve a similar effect. Second, the methods used in Commodore 64 BASIC are historically quite typical of computational approaches to pseudo-randomness since the 1950s. Finally, out of several common approaches to randomness available on the Commodore 64, 10 PRINT uses a very standard method that is well-suited to experimentation, debugging, and the production of canonical results, although this method is not without its deficiencies. |
[[Image:10print-nonrandom-205.png|160px|thumb|10 PRINT CHR$(205); : GOTO 10]] | [[Image:10print-nonrandom-205.png|160px|thumb|10 PRINT CHR$(205); : GOTO 10]] | ||
[[Image:10print-nonrandom-205-206.png|160px|thumb|10 PRINT CHR$(205)CHR$(206); : GOTO 10]] | [[Image:10print-nonrandom-205-206.png|160px|thumb|10 PRINT CHR$(205)CHR$(206); : GOTO 10]] | ||
| − | 10 PRINT prints a wrapping series of diagonal lines; these unpredictably alternate between left and right. This unpredictability is crucial to producing the impression of a maze. A quick look at variations of 10 PRINT that have regular or no alternation should make it clear that the randomness in the program is significant. | + | 10 PRINT prints a wrapping series of diagonal lines that alternate between left and right unpredictably. This unpredictability is crucial to producing the impression of a maze. Looking at variations of 10 PRINT that have regular or no alternation make it clear that the randomness in the program is significant. |
| − | This aesthetic issue extends to both the appearance of the final output and the code. While it is possible to implement one's own pseudo-random number generator in a BASIC program, it would have lengthened and complicated 10 PRINT considerably if someone had added such code to it. It would certainly not have been a concise and elegant one-liner that fit into the MAGIC section of ''RUN.'' | + | This aesthetic issue extends to the appearance of the final output and the code. It is possible to implement one's own pseudo-random number generator in a BASIC program, but it would lengthen and complicate 10 PRINT considerably if someone did dd such code to it. It would certainly not be a concise and elegant one-liner that suited the MAGIC section of ''RUN.'' |
In 10 PRINT, random numbers are provided through RND, one of ten mathematical functions available in BASIC since the earliest version of the language. As described the original Dartmouth BASIC manual (1964), RND produces a "new and different random number" between 0 and 1 "each time it is used in a program" (39). Thus, calling RND(1) might return 0.185564016 the first time, 0.0468986348 the second, and 0.827743801 the third, with no apparent pattern between one number and the next. (These are in fact the numbers that RND(1) returns initially on the Commodore 64.) These numbers could then be used to drive unpredictable processes, as in fact they do drive the coin-toss decision between diagonal lines in 10 PRINT output. A similar process might also determine the direction changes of ghosts in ''Ms. Pac-Man'' or the way other game elements appear or behave. | In 10 PRINT, random numbers are provided through RND, one of ten mathematical functions available in BASIC since the earliest version of the language. As described the original Dartmouth BASIC manual (1964), RND produces a "new and different random number" between 0 and 1 "each time it is used in a program" (39). Thus, calling RND(1) might return 0.185564016 the first time, 0.0468986348 the second, and 0.827743801 the third, with no apparent pattern between one number and the next. (These are in fact the numbers that RND(1) returns initially on the Commodore 64.) These numbers could then be used to drive unpredictable processes, as in fact they do drive the coin-toss decision between diagonal lines in 10 PRINT output. A similar process might also determine the direction changes of ghosts in ''Ms. Pac-Man'' or the way other game elements appear or behave. | ||
