Randomness

From Maze

(Difference between revisions)
Jump to: navigation, search
Line 107:Line 107:
Reliability of the randomness. Point out that pseudo-randomness is not bad or inferior.
Reliability of the randomness. Point out that pseudo-randomness is not bad or inferior.
−
Although random numbers seem to against the concept of predictability, it turns out it is difficult to generate numbers that are extremely predictable. The Commodore 64 has two ways of making random numbers. The RND function in BASIC supplies two official means, while programmers have discovered several others, including using the sound chip and writing their own randomization algorithms.
+
Although random numbers seem to against the concept of predictability, it turns out it is difficult to generate numbers that are extremely predictable. The Commodore 64 included three ways of making random numbers out of the box. The RND function in BASIC supplies two official means, the sound chip, provides one. Programmers have been writing their own randomization algorithms.
On the Commodore 64, when RND(1) is called. It produces a deterministic sequence of random numbers.
On the Commodore 64, when RND(1) is called. It produces a deterministic sequence of random numbers.
Line 121:Line 121:
LCGs have some interesting properties. One of them is repeatability.
LCGs have some interesting properties. One of them is repeatability.
−
The C64 allows offered another way of doing it: RND(0). This uses the timer as a random number generator.
+
The C64 allows offered another way of doing it: RND(0). This uses the timer as a random number generator.
−
 
* How Randomness Works, what it's good for
* How Randomness Works, what it's good for
Line 139:Line 138:
 +
* Alternative methods of finding randomness within the C64.
 +
* Use multiple seeds, then SID register random
 +
SID Noise
−
* Alternative methods of finding randomness within the C64.
+
It was possible on the C64 to get random values from the Sound Interface Device (SID) chip. Reading from register 27 (decimal) returns the current value of oscillator 3. If it's set to noise, you get a random number generator.
 +
 +
<pre>
 +
5 s=54272:poke s+15,100:pokes+18,128
 +
10 print peek(s+27):goto 10
 +
</pre>
 +
 +
<pre>
 +
10 s=54272:pokes+15,100:pokes+18,128:printchr$(205.5+(peek(s+27)and1));:goto10
 +
</pre>
 +
 +
<pre>
 +
5 s=54272:pokes+15,100:pokes+18,128
 +
10 print chr$(205.5+(peek(s+27)and1));:goto10
 +
</pre>
 +
 +
<pre>
 +
6 poke 54272+wave, noise
 +
10 print chr$(205.5+peek(54272+osc3read));goto 10
 +
</pre>
 +
Assembly routine (Ian)
Assembly routine (Ian)
Line 156:Line 178:
</pre>
</pre>
−
 
−
SID Noise
 
−
 
−
It was possible on the C64 to get random values from the Sound Interface Device (SID) chip. Reading from register 27 (decimal) returns the current value of oscillator 3. If it's set to noise, you get a random number generator.
 
−
 
<pre>
<pre>
−
5 rem init sid for noise
+
5 rem simplified random number generator
−
6 poke 54272+wave, noise
+
6 a = 1
−
10 print chr$(209.5+peek(54272+osc3read));goto 10
+
10 a = a*2
 +
20 if a >= 256 then goto 30
 +
25
 +
30 random = a: print radnom: goto 10
</pre>
</pre>
−
* Use multiple seeds, then SID register random
 
−
* How it could be used to teach someone randomness/probability
+
 +
 +
Line 178:Line 199:
−
+
* How it could be used to teach someone randomness/probability
* Prg in User guide demo of biasing randomness
* Prg in User guide demo of biasing randomness

Revision as of 21:45, 12 May 2011

View this revision of Randomness.

Personal tools