Initial revision
[ssr] / StraySrc / Libraries / Sapphire / sh / rand
1 ;
2 ; rand.sh
3 ;
4 ; Generating random numbers
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Sapphire library.
12 ;
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Overview -------------------------------------------------------------
28 ;
29 ; Functions provided:
30 ;
31 ; rand
32 ; rand_setSeed
33 ; rnd
34 ; rand_init
35
36 [ :LNOT::DEF:rand__dfn
37 GBLL rand__dfn
38
39 ; --- rand ---
40 ;
41 ; On entry: --
42 ;
43 ; On exit: R0 == a pseudorandom number between 0 and &7FFFFFFF
44 ;
45 ; Use: Returns a pseudorandom number. The algorithm used is the
46 ; additive generator found in Knuth. The table is generated
47 ; from the current monotonic time using a linear congruential
48 ; generator. Randomness is fairly good, and it's very quick.
49
50 IMPORT rand
51
52 ; --- rand_setSeed ---
53 ;
54 ; On entry: R0 == a pseudorandom seed
55 ;
56 ; On exit: --
57 ;
58 ; Use: Sets up the random number generator (rand) to the given start
59 ; position. The table of values is initialised from the seed
60 ; in a psuedorandom manner, using a linear congruential
61 ; generator.
62
63 IMPORT rand_setSeed
64
65 ; --- rnd ---
66 ;
67 ; On entry: R0 == start value (inclusive)
68 ; R1 == end value (inclusive)
69 ;
70 ; On exit: R0 == random number between the boundaries given
71 ;
72 ; Use: Returns a random integer between the boundaries given.
73 ; The distribution is slightly skewed towards lower numbers,
74 ; but there's not a lot I can do about this, folks.
75
76 IMPORT rnd
77
78 ; --- rand_init ---
79 ;
80 ; On entry: --
81 ;
82 ; On exit: --
83 ;
84 ; Use: Initialise the random number table.
85
86 IMPORT rand_init
87
88 ]
89
90 ;----- That's all, folks ----------------------------------------------------
91
92 END