[Index] [Previous] [Next]

2.12 RND - Optional Function #2

 

Rnd

Generates a random number. This is a bit odd... like all inline functions it takes a numeric argument, but in RNDs case this argument is mostly ignored. If it's a negative number it skips a couple of stages of reseeding RND_SEED.

If tghe argument in FACCUM is negative, then skip over the
0C5F EF Rnd RST FTestSign
0C60 FA7C0C JM 0C7C
Load the seed into FACCUM.
0C63 21910C LXI H,RND_SEED
0C66 CD0F0A CALL FLoadFromMem
0C69 C8 RZ
Multiply seed by 11,879,546.
0C6A 013598 LXI B,9835
0C6D 117A44 LXI D,447A
0C70 CDE508 CALL FMul+2
Add 0.00000003927678
0C73 012868 LXI B,6828
0C76 1146B1 LXI D,B146
0C79 CD1208 CALL FAdd+2
Swap first and third mantissa bytes.
0C7C CD1D0A CALL FCopyToBCDE
0C7F 7B MOV A,E
0C80 59 MOV E,C
0C81 4F MOV C,A

Set FTEMP_SIGN to 0x80 to indicate to FNormalise that it doesn't need to change the sign. Also set FACCUM's exponent to 0 so the result, when normalised, will be less than 1.

0C82 3680 MVI M,80
0C84 2B DCX H
0C85 46 MOV B,M
0C86 3680 MVI M,80
0C88 CD5E08 CALL FNormalise+3
Exit via a copy of the result to RND_SEED so it can be used for the next time RND is called.
0C8B 21910C LXI H,RND_SEED
0C8E C3290A JMP FCopyToMem
Seed for random number generation.
0C91 52C74F80 RND_SEED 0.811635

 


[Index] [Previous] [Next]