SeedRnd problems

BlitzMax Forums/BlitzMax Programming/SeedRnd problems

dmaz(Posted 2008) [#1]
other than using SeedRnd, does anybody know of anything else that can "seed" or disrupt the predictability of the blitz random functions?

I want to generate the same random values so I use SeedRnd with a static value of course. I get the correct values at first but I soon start seeing Rand and Rnd start giving me "random" values that are not from the seed I fed it. I can't find a seedrnd anywhere in any of my program's code even while searching through all the mod sources also.

I've traced where it happens in my program at a macro level but there is a lot code yet to go through. in any case, there is not a seedrnd...


GfK(Posted 2008) [#2]
You sure you aren't doing something like this:
SeedRnd 12345

Print "Set 1"
Print Rnd(0,1)
Print Rand(0,100)
Print Rnd(0,1)


SeedRnd 12345
Print "Set 2"
Print Rand(0,100)
Print Rnd(0,1)
Print Rnd(0,1)

Same seed, same three calls to Rand/Rnd (only in a slightly different order), different results.


Brucey(Posted 2008) [#3]
Try using a more predictable randomness generator? :-)


dmaz(Posted 2008) [#4]
You sure you aren't doing something like this

yeah, pretty sure since I only have one seedrnd and from that I should see the same stream of rnd numbers, which mean my code will take the same path and ask for the same random numbers.

Try using a more predictable randomness generator?

well, blitz's is pseudo random and has always been predictable for me in the past... I know it's something I must be doing but I can't seem to find it or even think what it could be.


ima747(Posted 2008) [#5]
I think Gfk is pointing at the most likely cause of your problem. Every time you pull a number from the random number generator, it re-randomizes for the next number in essence. So the order and type of number you pull must be exactly the same or you will be introducing a random element into the random list... I think that makes sense.

Double check all your code between when you get a predictable random number and when it starts going wonky, I would expect you have a branching random-get of some kind. Like if the user has clicked something then get a random number else do something else, if the user clicked something you should see a totally different string of random values past that point than if they haven't since it will have taken the top random number and broken your sequence.

If you can't track it down, or if it's a glitch on the pseudo random making it... really random, then another option might be to create a list or array of random numbers at the start and create your own rand functions to pull from the list. The list will be static since you seed, generate random numbers, store in list at the same point every time, there's no possibility for error. You just need a big enough list to satisfy your program's needs. This is a really ugly method and would waste some memory and cause some load time, but on any semi modern computer you should be able to generate the list in a fraction of a second and storage should be on the order of kb so not a real concern. It could have the added benefit of actually using less processor time when you need it (i.e. durring execution) if you use an array since all it has to do is check the array position rather than run the random generation functions... but again, trivial processor time either way.

I'm not above a dirty solution but I would certainly go looking for a mystery call to rand first just to try to figure out why it was going wrong in the first place...


dmaz(Posted 2008) [#6]
I found it, gfk and ima747 were right... jeez, a place I hadn't looked... I had one rnd call in my one of my draw routines instead of the update routine. the draw routine is independent of the update and runs full speed and so can have different fps which mean for every update I will have a varying number of draw calls.

thanks guys.