Rnd

From Maze

(Difference between revisions)
Jump to: navigation, search
Line 1:Line 1:
−
this page is for collecting information about the random function (RND) as used in the commodore 64 program
+
 +
5. Randomness
 +
Among other things, the program being discussed is a display of (near) randomness,
 +
which is often mentioned in digital media discussions but seldom explored in depth.
 +
The “pseudo-random” capability of the computer far exceeds a human’s
 +
randomization ability and is core to many areas of computing, including graphics
 +
(Perlin noise) and communication (random backoff for Ethernet).
 +
 +
 +
The random function (RND) as used in the commodore 64 program
10 print chr$(79+int(rnd(0)*2));:goto 10
10 print chr$(79+int(rnd(0)*2));:goto 10
−
some useful links:
+
C64-specific:
−
 
−
C64-specific
 
[http://www.c64-wiki.com/index.php/RND Brief descrip of command]
[http://www.c64-wiki.com/index.php/RND Brief descrip of command]
 +
rnd(1) is a deterministic sequence of random numbers
 +
Rnd(0) means use the timer as the random number generator
 +
[http://www.ffd2.com/fridge/docs/c64-diss.html disassembly of C64 ROMs]
[http://www.ffd2.com/fridge/docs/c64-diss.html disassembly of C64 ROMs]
 +
This is a commented disassembly of the C64 ROM. Elsewhere, I've quoted the relevant code to perform RND() in C64 Basic.
 +
 +
[http://www.devili.iki.fi/Computers/Commodore/C64/Programmers_Reference/Chapter_5/page_311.html C64 prog. ref. manual (zero page addresses) ]
[http://www.devili.iki.fi/Computers/Commodore/C64/Programmers_Reference/Chapter_5/page_311.html C64 prog. ref. manual (zero page addresses) ]
 +
 +
This is a reference to assist in interpretation the the above disassembly.
 +
 +
Line 17:Line 34:
[http://dtss.dartmouth.edu/scans/BASIC/ Dartmouth BASIC code]
[http://dtss.dartmouth.edu/scans/BASIC/ Dartmouth BASIC code]
 +
This shows that the Dartmouth Basic (the first BASIC), had a similar specification for the RND(x) function. It generated a single stream of pseudorandom numbers. Interestingly, it recommends throwing away the first "115" or so numbers.
 +
 +
Survey of Random Number algorithms
Survey of Random Number algorithms
 +
 +
These are rather technical in nature, but can be used to contextualize the "quality" of the random number generator used in the C64 by comparing it with those used today in languages like Java and Python (need more lingos?).
[http://random.mat.sbg.ac.at/~charly/server/node3.html specific LCG algorithms and quality]
[http://random.mat.sbg.ac.at/~charly/server/node3.html specific LCG algorithms and quality]
Line 28:Line 50:
[http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html random in Java ]
[http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html random in Java ]
 +
(Java)
 +
The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.)
 +
[http://docs.python.org/library/random.html random in python ]
[http://docs.python.org/library/random.html random in python ]
−
 
−
 
−
Notes
 
Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence. However, being completely deterministic, it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes.
Python uses the Mersenne Twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1. The underlying implementation in C is both fast and threadsafe. The Mersenne Twister is one of the most extensively tested random number generators in existence. However, being completely deterministic, it is not suitable for all purposes, and is completely unsuitable for cryptographic purposes.
−
(Java)
 
−
The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.)
 
 +
 +
 +
 +
 +
 +
* This an excerpt of the relevant parts of the C64 BASIC and Kernal ROMs which implement the RND(1) function in the titular program.
 +
perhaps we can depict this function somehow.
C64 Rnd(0) Disassembly
C64 Rnd(0) Disassembly

Revision as of 22:19, 29 April 2010

View this revision of Rnd.

Personal tools