Random.Range vs Random.RandomRange

Noticed that autocomplete also has Random.RandomRange available as well as Random.Range. Was wondering if anyone knew what the difference is here and why you would choose one over the other. Cheers

Hi @shotty, welcome to the community :slight_smile:

Looking at this article it could be that Random.RandomRange has been made obsolete and replaced with Random.Range. Based on the age of that article though, I’d be surprised if it had still been left in a 2017 build, I’m guessing that is the version of Unity you are using.

Do you have using System; at the top of your class by any chance?

1 Like

Hi Rob, thanks for the reply! I did indeed have using System at the time but have since removed it as per the instructions in the series. I’m assuming it was a part of that library?

Hi,

Yes, that’s correct, it occurs in both. That is a less than ideal situation but can sometimes occur if you have multiple libraries in use at once. Another way to work around it is to specific the namespace in front of the usage, but it gets a bit messy, sometimes unavailable though, for example;

int randomValue = UnityEngine.Random.Range(min, max);

In the above, you are specifically stating “use the Unity one” :slight_smile:

Hope this helps.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms