Forum
Randomize does not change the Seed (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Randomize does not change the Seed (*solved*) (/showthread.php?tid=280)



Randomize does not change the Seed (*solved*) - LCD - 08-16-2010

Another bug i discovered in the latest dev version is that RANDOMIZE does not change the seed.
I got exactly the same RND numbers with RANDOMIZE 0 as with RANDOMIZE 1 or even RANDOMIZE (without number, after a pause 0 to avoid the fact that the emulator always starts with frame count 0 and uses it as Seed.
Here is the evidence:
Code:
print "Actual Seed: ";peek (uinteger,23670)
randomize 45
print "Seed after Random 45: ";peek (uinteger,23670)
randomize 37
print "Seed after Random 37: ";peek (uinteger,23670)
randomize
print "Randomized seed: ";peek (uinteger,23670)
There is a way around it:
Code:
poke uinteger 23670,peek (uinteger,23672)
This does not rely on RANDOMIZE, it just copies two bytes from frames sysvar to seed sysvar, and gives you every time you start a program, new RND sequence (After a PAUSE 0 or selecting controls).


Re: Randomize does not change the Seed - boriel - 08-16-2010

LCD Wrote:Another bug i discovered in the latest dev version is that RANDOMIZE does not change the seed.
I got exactly the same RND numbers with RANDOMIZE 0 as with RANDOMIZE 1 or even RANDOMIZE (without number, after a pause 0 to avoid the fact that the emulator always starts with frame count 0 and uses it as Seed.
Here is the evidence:
Code:
print "Actual Seed: ";peek (uinteger,23670)
randomize 45
print "Seed after Random 45: ";peek (uinteger,23670)
randomize 37
print "Seed after Random 37: ";peek (uinteger,23670)
randomize
print "Randomized seed: ";peek (uinteger,23670)
There is a way around it:
Code:
poke uinteger 23670,peek (uinteger,23672)
This does not rely on RANDOMIZE, it just copies two bytes from frames sysvar to seed sysvar, and gives you every time you start a program, new RND sequence (After a PAUSE 0 or selecting controls).
I will debug this. But RANDOMIZE now relies in 32 Bit seeds being lower 16-bit SEED system var (23670, 23671) and two upper 16bits in a reserved memory position. I will check this bug.

Thanks!


Re: Randomize does not change the Seed - boriel - 08-16-2010

Ok, It was a silly bug. It's been fixed. Please re-download.
Also note this beta (alpha?) version supports bOR, bAND, bNOT, bXOR in 8 bit integers.

16 and 32 are not included yet (still buggy). If you try those, the compiler will stop with an strange error.


Re: Randomize does not change the Seed - LCD - 08-16-2010

boriel Wrote:Ok, It was a silly bug. It's been fixed. Please re-download.
Also note this beta (alpha?) version supports bOR, bAND, bNOT, bXOR in 8 bit integers.

16 and 32 are not included yet (still buggy). If you try those, the compiler will stop with an strange error.
Cool anyway! Thanks, I will download and install it. Even 8 bit only binary manipulation is worth it.