SERIOUS Seed Bug

Archives Forums/BlitzPlus Bug Reports/SERIOUS Seed Bug

Vic 3 Babes(Posted 2007) [#1]
This is bad.

SeedRnd $24E7AC60
a=Rand(0,8)
Print a
Input b$

The random number generated is 9.

Bit of a problem when you are picking a random column for a number when generating a Sudoku puzzle when the Sudoku array is only (8,8) - Array Index out of Bounds.

So I wrote some code to see how often this happens - I stopped it from running after it found the first 9 seeds that cause Rand() to return numbers outside the specified range. That means that I only checked the first

267,250,961 positive seeds from a possible
2,147,483,647 - not counting the negative seeds.

If you run the following code, you will see that all nine of these seeds caused Rand(0,8) to return 9.

For x=1 To 9
	Read a
	SeedRnd a
	Print Rand(0,8)
Next
b$=Input$()	;for pause purposes

Data $012ADB51,$03b0c470,$04db9fc1,$076188e0,$088c6431
Data $0b124d50,$0c3d28a1,$0ec311c0,$0feded11


What's even more bizarre - given that I already know that Blitz2D doesn't generate the same random numbers from the same seeds as BlitzPlus, is that when I run the final piece of code above in Blitz2D - all of the above seeds return 8 (including the seed in the first example that caused my prog to crash).

So maybe there isn't an algorithmic difference in the random number generators afterall - just a few bugs in the BlitzPlus version.


Floyd(Posted 2007) [#2]
...when I run the final piece of code above in Blitz2D - all of the above seeds return 8

And also in Blitz3D.


Vic 3 Babes(Posted 2008) [#3]
So, anything happening?


Ross C(Posted 2008) [#4]
Someone wrote a better random number generator. Morduun i think? You could search the code archives.


Dabhand(Posted 2008) [#5]

Someone wrote a better random number generator. Morduun i think? You could search the code archives.



http://www.denathorn.co.uk/Files/mersennetwist.zip

I'm sure thats it! :)


Rob Farley(Posted 2008) [#6]
You could always work round the problem by sticking a Mod 9 On the end of it.

Print Rand(0,8) Mod 9

I accept not an ideal solution, but you won't get any out of range errors and the results will be predictable.


CloseToPerfect(Posted 2009) [#7]
Funny thing when you use rnd instead of rand it works fine.