- Home /
Why aren't my random numbers random?
Hello,
So I'm having this odd issue lately where the random number I generate is the same every single time I play my game. I'm using Photon Networking if that makes any difference.
Here's the snippet of my code:
windDirection = Random.Range (1,361);
windSpeedMult = Random.Range (1.0f, 2.0f);
Same values every time. Any help would be greatly appreciated!
Thanks!
Have you written any code that sets Random.seed? Have you imported any plugins that might do so? If you always set the same seed, you'll always get the same results.
Is this variable being set at the start of the code or during? I think Randoms have to be called every time you want it to get a random one or else it's basically just getting one random number and saving it to the variable.
Seems like something in your project is causing the problem. If you haven't, I would get in $$anonymous$$onoDevelop and try a "find in files..." for "Random.seed" (I believe the option is Ctrl+Shift+F in Windows).
Also make sure to check your console window for any errors or warnings. I don't imagine any would turn up, here, but it's always a good idea to check.
If that doesn't turn up anything, you may have to try disabling plugins and/or components until the problem stops.
Amazing. There was a inconspicuous script from a package I added recently that set a random.seed. Commented out the line and it's fixed! Thank you so much! Feel free to post it as the answer so I can choose it!
Answer by rutter · May 30, 2014 at 01:05 AM
Posting answer from comments:
Have you written any code that sets Random.seed? Have you imported any plugins that might do so? If you always set the same seed, you'll always get the same results.
If you haven't, I would get in MonoDevelop and try a "find in files..." for "Random.seed" (I believe the option is Ctrl+Shift+F in Windows).
Your answer
Follow this Question
Related Questions
Random.Range is the same in each object with the script 0 Answers
Random.Range is not changing? 1 Answer
Random.range multiple instantiations without repetition 1 Answer
Rolling random numbers 3 Answers