1 XEROX COMMON LISP DESIGN DOCUMENT CMLRAND 1 CMLRAND 6 Kelly Roach 24-MAR-86 Section 12.9. Random numbers. 2 Issues 1 (1) Common Lisp (RANDOM NUMBER &OPTIONAL STATE) not like Interlisp (RAND LOWER UPPER). (2) Global variable *RANDOM-STATE*. Random state objects. Printing and reading forms like #S(RANDOM-STATE DATA #(14 49 98436589 ...)) as described on p231 of silver book. (3) No Common Lisp RANDSET function. 2 Decisions 1 (1) Keep Interlisp IL:RAND in addition to implementing Common Lisp RANDOM, but also implement CL:RAND to be (CL:RAND LOWER UPPER &OPTIONAL STATE) which is sort of an extension of RAND. Eventually IL:RAND=CL:RAND? (2) Implement, adapting existing Interlisp RAND & RANDSET code. All existing calls in the system to RAND should be changed to use their own private random state rather than default to *RANDOM-STATE* which is intended for the user. (3) Eventually (RANDSET X) = (SETQ *RANDOM-STATE* X)? Not completely backwards compatible since we choose that random states will not be a list of 55 SMALLPs any longer. 2 Design overview 1 (1) Implement Common Lisp fns ignoring reading and printing random states. (2) Then implement reading and printing random states. 2 Algorithms and Data Structures 1 (1) Use existing Interlisp RAND & RANDSET code to implement Common Lisp RANDOM, MAKE-RANDOM-STATE, RANDOM-STATE-P. (2) Extend RAND to (RAND LOWER UPPER &OPTIONAL STATE) (3) Random states. Currently RANDSET accepts and returns a list of 55 SMALLPs. It's a fair guess that RAND doesn't manipulate this list directly but some kind of array that RANDSET reads into and reads out of. Since Common Lisp RANDOM could be expected to be routinely passed a STATE, it is better to make Common Lisp random states like the internal array than the external list that RANDSET takes and gives. Do reading and printing of random states after (1) above, (2) above, and everything else to CMLRAND implemented. Dependencies 1 Might be handy to have working DEFSTRUCT for defining random states. Not crucial on first pass. Performance points 1 Compiler / evaluator: N/A Optimizer macros: N/A Microcode: None Environment support 1 Environmental impact (tools needed, etc.): None Tasks 1 (1) Implement RAND. (2) Impelement reading and printing of random states. Testing issues 1 (1) Eventually should CL:RAND replace IL:RAND: There are a lot of demoish and gamish packages that call RAND that should be tested. Example COLORDEMO. (2) Eventually should CL:RAND replace IL:RAND: More serious are some network calls to RAND. They should not be using *RANDOM-STATE* which is what STATE=NIL will default to. See that networking activity does not side effect *RANDOM-STATE*. (3) Test cases: (a) (RANDOM 100) = random integer? (b) (FOR I FROM 1 TO 200 DO (PRINT (RANDOM 50))) = no error such as array index out of bounds? (c) (RANDOM 100.0) = random float? (d) (MAKE-RANDOM-STATE) = random state? (e) (MAKE-RANDOM-STATE STATE) = random state like STATE? (f) (MAKE-RANDOM-STATE T) = random state? (g) (RANDOM-STATE-P STATE) = works and is defined? (h) If you print *RANDOM-STATE* to a file, can you read it back in OK? 2 Phasing and Timing 1 The implementation is phased: (1) Everything but reading and printing of random states. (2) Reading and printing of random states. Time estimate: 1 week. Permission to modify demos, games, network code needed perhaps. 2 Appendix 1 (RAND NUMBER &OPTIONAL STATE) *RANDOM-STATE* (MAKE-RANDOM-STATE &OPTIONAL STATE) (RANDOM-STATE-P OBJECT) (LIST ((PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD RIGHT) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC)) (288 12 288 36) NIL) (HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (HEADING NIL (HEADINGTYPE RECTOHEAD) (72 762 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD RIGHT) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC)) (288 12 288 36) NIL) (HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (HEADING NIL (HEADINGTYPE RECTOHEAD) (72 762 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))))) /``øT/øT/ øT)T)2T(`` )``T)`` TBøø PAGEHEADING RECTOHEADAøø PAGEHEADINGFOOTINGRMODERN MODERNMODERNMODERN   HRULE.GETFNMODERN  "   HRULE.GETFNMODERN  HRULE.GETFNMODERN HRULE.GETFNMODERN HRULE.GETFNMODERNW¯% HRULE.GETFNMODERN  HRULE.GETFNMODERNÖè« HRULE.GETFNMODERN HRULE.GETFNMODERNK7 HRULE.GETFNMODERN HRULE.GETFNMODERNs6  HRULE.GETFNMODERN a HRULE.GETFNMODERN  HRULE.GETFNMODERN 0 HRULE.GETFNMODERN 6 HRULE.GETFNMODERN ™ò#_#(9*3G HRULE.GETFNMODERN HRULE.GETFNMODERN:+@ HRULE.GETFNMODERN  HRULE.GETFNMODERN% ¼°zº