Need help with a Random Number Generator in Unity C#

Started by
21 comments, last by Lactose 7 years, 5 months ago

Initialise/seed the random number generator (in this case, UnityEngine.Random.InitState) exactly once. Ideally at the start of the program.

Ask the random number generator for a new value every time you need one.

Here, you have the Random.InitState and the Random.Range in the same RNG function, so it won't work. You end up basically just asking it for the system time whenever you call it.

And you still only ever set 'n' once so the outcome of ChooseRandomly is predetermined, and chosenGameObject will always be the same.

Advertisement

Incredible! Its working perfectly. I have a splash screen where I create objects that are used throughout the game so I stuck a RNG initializing script onto that scene and I ask for a new number from RNG every time during the loop. It works like a charm! Thank you everyone for your help. This thread is done, please close it!

This thread is done, please close it!

GDNet does not generally close threads.

Others reading this might still have questions, comments or suggestions -- closing threads would shut down the possibility of continuing the discussion even if the thread starter has achieved the results they want.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement