Prev: 9BDF Up: Map Next: 9BFD
9BF4: Random number from 0 to A
Returns the absolute value of a random number from -A to A (9BFD). Because of the way 9BFD squeezes its random byte into range, the results are not all equally likely: for A=4, 0 and 4 come up half as often as 1, 2 and 3; for A=3 the four results are equally likely; for A=9 the higher numbers are favoured.
Input
A Range
Output
A Random number
9BF4 CALL $9BFD Get a random number from -A to +A
9BF7 BIT 7,A Is it negative (bit 7 set)?
9BF9 RET Z No: a positive result is fine as it is
9BFA NEG Yes: make it positive, since this routine only ever wants a number from 0 upwards
9BFC RET
Prev: 9BDF Up: Map Next: 9BFD