Post by 10loadgameplay on Feb 18, 2013 13:10:12 GMT
I have found I could only generate a valid random number if the Getrandom value was certain 8 bit values E.g 7, 55, 71, 95. Not sure if this is me seeing a pattern in the numbers or just chance, but these seemed to generate random sequences. 128 for example generates only 028 & 128!
I tested this with: Delay 6 GETRANDOM X Display RND
I still use GETRANDOM in my code for in-game events that do not require absolute randomness, for instance bonus/malus items generation.
However, for more serious applications, e.g. when objects the player has to find are scattered around a level at the start, I employ a solution based on the refresh register, suggested by John Connolly.
Before the level starts, the management program executes this code:
LD A,R ; Load the A register with the refresh register LD L,A ; Copy register A into register L AND %00111111 ; This masking prevents the address we are forming from accessing RAM LD H,A ; Copy register A into register H LD A,(HL) ; Load the pseudo-random value into A
; optional code if you just need values 0, 1, 2 or 3 ; AND %00000011 ; masking to return 0, 1, 2 or 3 ; LD (variable),A ; a variabile in AGD is loaded with the value of A Link to the original article