|
Post by alessandro on Feb 16, 2013 22:31:01 GMT
The GETRANDOM command does not seem to generate "random" numbers and often includes its argument as a result, which shouldn't be allowed according to the documentation. Some examples follow.
GETRANDOM 2 always generates 0 or 2.
GETRANDOM 4 always generates 0 or 4.
GETRANDOM 5 generates 0, 1, 4 or 5.
GETRANDOM 6 generates 0, 2, 4 or 6.
GETRANDOM generates only 0 or 8.
GETRANDOM 9 generates only 0, 8 or 9.
A more "random" behavior is obtained with GETRANDOM 3 and 7.
|
|
|
Post by BiNMaN on Feb 17, 2013 17:11:39 GMT
also I find the GETRANDOM generator will choose 0 more often over other numbers, so in general the higher the value you choose the less likely it will result in 0
|
|
|
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
X being your parameter.
|
|
|
Post by alessandro on Feb 25, 2013 13:43:13 GMT
Unfortunately GETRANDOM seems to be not "random" at all even in version 3.4 (see the relative thread for details).
|
|
|
Post by nra on Feb 4, 2019 3:24:08 GMT
Guys, is it emulators issue, or v4.7 also gives not so random values in the editor?
How can one mitigate it, a poke, AGDX, or a BASIC loader/RANDOMIZE?
TY
|
|
|
Post by alessandro on Feb 4, 2019 16:41:16 GMT
Hi nra, 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
|
|