I have a need in a project for more than one instance of the Random class. I have a complex terrain generation procedure that requires one Random class with a fixed seed and another with a variable seed.
The docs state:
For best results, you should only create a single instance of Random per app.
Why is this? Most other languages don’t enforce this so I’m curious about Xojo’s implementation. Is it possible to instantiate more than one instance (I understand that System.Random is a singleton).
I tried caching the current Seed value and subsequently restoring it but that doesn’t work because as soon as you assign to Random.Seed the pattern resets.
as Kem said : Generating complex passwords - #4 by Kem_Tekinay
a new system.random has the same seed and generate the same serie of numbers
so if you make more than one you may end up with the same numbers
using crypto.generaterandombytes gives you different numbers each time.
For best results, you should create a single instance of Random that you can use throughout your application. The App object is often a good place for this instance.
When I’ve used it, I’ve always followed their advice above.