- Home /
Does Random.Range() have a max return value?
I have a map generator that needs to get a random number between 0 and n.
When n < 150, the results seem fine. Random enough. However, when n > 150 the return values have never gone higher than 150.
Therefore, is the max result in Random.Range 150?
Can you paste your actual code so we can see how you are calling it?
Are you using Random.seed to seed your Random number generator?
I made this test script:
public class TestCode : $$anonymous$$onoBehaviour {
float fHighestNumber = 0;
float n = 150;
void
Start ()
{
for(int i = 0; i < 10000; i++)
{
float fRandomNumber = Random.Range(0, n);
if(fHighestNumber < fRandomNumber)
fHighestNumber = fRandomNumber;
}
Debug.Log (fHighestNumber);
}
}
And the results proved my question false. After that, it seems the problem is here:
[HideInInspector] public Vector3 v$$anonymous$$AP_SIZE = new Vector3 (20000, 0, 20000);
Somewhere in my code it sets the vector (50, 0, 50). Just cant seem to find where. That number gets multipled by 3, therefore we get 150.
Answer by NickWalker12 · May 25, 2012 at 08:04 PM
Nope.
Mistake in my code. Thanks for the help.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Random.Range not working, no errors given c# 1 Answer
Random Y Axis Direction On Prefab Within Boundaries (C#) 0 Answers
Multiple Cars not working 1 Answer