STREGAsGate / Raylib

A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go!
MIT License
110 stars 14 forks source link

Pseudo-RNG does not seem to work #13

Open JxD-DeciSion opened 1 year ago

JxD-DeciSion commented 1 year ago

[Raylib] - [Pseudo-RNG does not seem to work]

Description Since the .getRandomValue(min: , max:) method seems to be deprecated, I tried using Int32.random(in:)/Int.random(in:) as stated in the deprecation message. However, these methods do not seem to be affected by the .setRandomSeed() method. I even attempted to set the seed via srand() and srandom(), but this did not work either.

Steps to Reproduce

  1. Set the seed via .setRandomSeed() once (I did it in the beginning immediately after window initialization).
  2. Generate a random value using the method Int32.random(in:).
  3. Print the generated value to the console.
  4. Restart the application and repeat steps 1-3 using the exact same code/seed.

Current Behavior The generated values are not identical, nor are their sequences anywhere near identical. When using .getRandomValue(min: , max:), everything works fine.

Relevant Screenshots/Logs -

Environment Operating System: Ubuntu 20.04.6 LTS Project Version: master Swift Version: 5.6.2 Target: x86_64-unknown-linux-gnu

Troubleshooting Steps Taken I tried only setting the seed once at the very beginning. I used a hardcoded seed of '123'. I tried setting the seed via .setRandomSeed() as well as srand() and srandom(). For getting a pseudo-random value, I tried Int.random(in:), Int(random()), Int32.random(in:), as well as UInt32.random(in:). After getting a value from the PRNG, I restarted the application and did the exact same thing as before, expecting to get the exact same value. But the value I received was always different. I also tried replicating this in a playground environment, getting different values/sequences there as well.

Possible Solutions Maybe the problem is with my usage, but I'm uncertain.

Additional Information You can use .getRandomValue(min: , max:) as a workaround, regardless of its deprecation.