Randomness
From Maze
(Difference between revisions)
(→The SID: Sound as a second stochastic source: added header note) | (→The SID: Sound as a second stochastic source) | ||
| Line 165: | Line 165: | ||
==== The SID: Sound as a second stochastic source ==== | ==== The SID: Sound as a second stochastic source ==== | ||
| + | While its predecessors such as the Commodore PET were able to generate random numbers, the Commodore 64 added another separate source of randomness, the MOS Technology 6581 Sound Interface Device (SID) chip. The SID was inspired by professional synthesizer electronics, and featured among other things the ability to produce square waves, sawtooth waves, triangle waves, and pseudo-random "noise." | ||
| + | |||
| + | By setting oscillator 3 on the SID chip to generate noise, then reading a noise output value in from register 27, a C64 BASIC or assembly program can draw on a second source of random numbers that changed constantly at the currently set speed of the oscillator. Because the SID is a mixed-signal integrated circuit (with digital control ports and analog output ports), a common misconception about the SID has been that it is a source of "true" or "high-quality" hardware-based random number generation, producing analog noise that was somehow the result of an analog process -- perhaps thermal noise, shot noise, or some other physical measurement of quantum indeterminacy. | ||
| + | |||
| + | However, this is not the case. SID noise is digitally generated by a 23-bit linear feedback shift register (LFSR), another common form of deterministically generating pseudorandom numbers. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | ---- | ||
| + | [SUGGESTION: INTRODUCE THE FOLLOWING PROGRAMS BY DESCRIBING THE FUNCTION OF THE PEEK AND POKE AND WALKING READER THROUGH THE WAY THIS PROGRAMS CALL UPON THE SID] | ||
| + | |||
[Jeremy: On review, I'm not totally convinced of the value of working through complex textbook examples of using the SID with BASIC peek-poke (as below) -- particularly because use of the SID is already quite removed from the RND(1) method of how 10 Print does randomness, with RND(-x) and RND(0) / RND(TI) being closer. I'm more inclined to tersely summarize this material as one or two examples maximum, perhaps with direct reference to "Random Numbers In Machine Language For Commodore 64" (Neil Boyle) | [Jeremy: On review, I'm not totally convinced of the value of working through complex textbook examples of using the SID with BASIC peek-poke (as below) -- particularly because use of the SID is already quite removed from the RND(1) method of how 10 Print does randomness, with RND(-x) and RND(0) / RND(TI) being closer. I'm more inclined to tersely summarize this material as one or two examples maximum, perhaps with direct reference to "Random Numbers In Machine Language For Commodore 64" (Neil Boyle) | ||
http://www.atarimagazines.com/compute/issue72/random_numbers.php | http://www.atarimagazines.com/compute/issue72/random_numbers.php | ||
] | ] | ||
| − | |||
| − | Finally, it is possible to generate random number on the Commodore 64 without using either RND function, relying instead upon the Sound Interface Device (SID) chip to produce random "noise." Reading the SID from register 27 (in decimal format) returns the current value of oscillator 3. If it's set to noise, the SID doubles as a random number generator. [IT'S UNCLEAR HOW THIS WORKS...MORE EXPLANATION NEEDED FOR NON-PROGRAMMING READERS] | ||
| − | |||
| − | [SUGGESTION: INTRODUCE THE FOLLOWING PROGRAMS BY DESCRIBING THE FUNCTION OF THE PEEK AND POKE AND WALKING READER THROUGH THE WAY THIS PROGRAMS CALL UPON THE SID] | ||
<pre> | <pre> | ||
| Line 204: | Line 211: | ||
</pre> | </pre> | ||
| + | ---- | ||
| + | ---- | ||
=== Works Cited === | === Works Cited === | ||
