x


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?

more ▼

asked May 25 '12 at 07:38 PM

NickWalker12 gravatar image

NickWalker12
122 3 6 9

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?

May 25 '12 at 07:46 PM shadowriffe

I made this test script:

public class TestCode : MonoBehaviour {

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 vMAP_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.

May 25 '12 at 08:03 PM NickWalker12
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Nope.

Mistake in my code. Thanks for the help.

more ▼

answered May 25 '12 at 08:04 PM

NickWalker12 gravatar image

NickWalker12
122 3 6 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4371
x599
x111
x52

asked: May 25 '12 at 07:38 PM

Seen: 427 times

Last Updated: May 25 '12 at 08:04 PM