Randomness

From Maze

(Difference between revisions)
Jump to: navigation, search
(→The C64 and the RND Function)
(→The C64 and the RND Function)
Line 101:Line 101:
The C64 User's Guide introduces the concept of randomness using an example that sidesteps the origins of randomness in computing. There's no mention of nuclear fission or computer-generated literature. Randomness comes into play in the shape of a game, when it's necessary to, as the manual puts it, "simulate the throw of dice" (48)--an example that takes us back to pre-industrial notions of randomness.
The C64 User's Guide introduces the concept of randomness using an example that sidesteps the origins of randomness in computing. There's no mention of nuclear fission or computer-generated literature. Randomness comes into play in the shape of a game, when it's necessary to, as the manual puts it, "simulate the throw of dice" (48)--an example that takes us back to pre-industrial notions of randomness.
−
The MOS6510 chip powering the Commodore 64 featured three ways of generating random numbers. The RND function in BASIC supplies two official means, while the sound chip provides another route. In addition to these out of the box methods, programmers could also write their own randomization algorithms, similar to the way Von Neumann or Knuth attempted to generate random numbers through mathematical functions. In C64 BASIC, a simplified means of generating a random number might look like this:
+
The MOS6510 chip powering the Commodore 64 featured three ways of generating random numbers. The RND function in BASIC supplies two official means, while the sound chip provides another route. In addition to these out of the box methods, programmers could also write their own randomization algorithms, similar to the way Von Neumann or Knuth attempted to generate random numbers through mathematical functions.
−
 
−
<pre>
 
−
5 rem simplified random number generator
 
−
6 a = 1
 
−
10 a = a*2
 
−
20 if a >= 256 then goto 30
 
−
25
 
−
30 random = a: print random: goto 10
 
−
</pre>
 
−
 
−
This program produces [insert string of random numbers generated by program]
 
Of course, it's inefficient to need an entire routine such as this to generate random numbers. This is where the C64's RND function comes into play. As described above, when RND(1) is called on the Commodore 64, a deterministic sequence of random numbers is produced. The precise algorithm is called a linear congruential generator (LCG), first proposed by Lehmer in 1949, though the C64 version includes additional byte-swapping. The LCG begins with a common seed, and nearly every C64 in the world will respond the same way to the maze program because they all rely on this mode of random number generation.
Of course, it's inefficient to need an entire routine such as this to generate random numbers. This is where the C64's RND function comes into play. As described above, when RND(1) is called on the Commodore 64, a deterministic sequence of random numbers is produced. The precise algorithm is called a linear congruential generator (LCG), first proposed by Lehmer in 1949, though the C64 version includes additional byte-swapping. The LCG begins with a common seed, and nearly every C64 in the world will respond the same way to the maze program because they all rely on this mode of random number generation.

Revision as of 16:27, 16 June 2011

View this revision of Randomness.

Personal tools