Related to my other post, I’m using the Random class. I think there is a bug (or at least incorrect documentation) with the Random.RandomizeSeed method. Take this code:
System.Random.Seed = 0
Var a As Double = System.Random.Number
System.Random.RandomizeSeed
Var b As Double = System.Random.Number
System.Random.Seed = 0
Var c As Double = System.Random.Number
System.Random.RandomizeSeed
Var d As Double = System.Random.Number
I am no expert but this is the result I thought you should get.
And the piece of documentation you quoted seems ok to me. The key word is “pseudo”.
The sequence of numbers is not random, but “pseudo” random. You don’t know what you will get, but the numbers are set with the seed.
That way you can get the same series of numbers using the same seed, which may be convenient for debugging (I am not saying this is the reason why it works this way, just that it can be advantageous some times).
A great thread I have used in the past for RND, RANDOM, etc is the following one: The limits of Rnd - General - Xojo Programming Forum
In your specific instance I think what you are getting is as expected. When you seed the class (at whatever instance you do it) the next call will use the same seed every time. The following paragraph I believe tries to explain this:
You might use this when you want to re-initialize a Random object but don’t want to create an entirely new one. If you are creating multiple sequences, this helps to make the sequences unrelated to one another.
In other words, the sequence after the call will always be the same (but you can keep making the seed call to generate new sequences). If you call the class without using the seed property/method you should get different results (i.e. not the same sequence every time you call it) - i.e. more so like the RND function.
The issue is not that the sequence is the same (that’s expected if the seed is the same). The issue is that I’m not convinced the Random class is actually picking a new seed when you call RandomizeSeed().
So you provide a fixed seed and that works
I thought you were (and are) saying that RandomiseSeed doesnt pick a random starting point.
If that is the case as the bug isnt fixed, use Ticks to set a seed that you wouldnt be able to predict
The effect is pretty much the same?
The specific issue I have is that I have a loop that generates some terrain. During testing, I set the seed before the loop to a known number (0 in this case) for repeatability. I then call other functions later that I want to have a random (i.e. not known) seed.
I could use System.Microseconds or System.Ticks (that’s what I have settled on) but the docs suggest that Random.RandomizeSeed() should do what I want. In actuality, it doesn’t.
I think @MarkusR is correct. It’s applying a fixed increment after the seed before. The docs should be more clear.
For map generation, wouldn’t you want predictable results? So the same seed always generates the same result? This is how it’s done in every game I’ve played.