Multiple instances of script generating the same random number
Howdy! I'm currently making a psudo-turnbased game where after a bar fills, the enemy will attack. But if the AI chooses to attack earlier then it will be a weaker attack, thus I need them to randomly choose when to attack.
I have tried multiple ways of implementing the randomness but with no success. I currently have the random in a totally separate static script and it still doesn't stop the enemies from attacking at the same time.
I understand that it's because Random is grabbing/using the same seed for each instance of the script and I can't get it to do otherwise.
I would need to see an example of what you are doing. Using Random.Range should produce different results (obviously dependent on how many #'s your trying to get against the depth of the range). Can you post the example of you using it?
Answer by DenisGLabrecque · Aug 10, 2019 at 08:35 AM
Random rand = new Random(); // Creates the random object from which random numbers are generated rand.Next(); // Gets a random number
Debug the random values. If they are truly random, your problem is a logic error elsewhere.
Your answer

Follow this Question
Related Questions
Random.Range code problem or problem with Unity? 1 Answer
how to randomly instantiate prefabs but each with it's own probability? 2 Answers
How do I generate a random number in regular time intervals? 0 Answers
What range of values need to be inserted if we need to pull a random item from the list? 0 Answers
Can I generate values outside of the Random.insideUnitCircle?? 1 Answer