# Question about how Random.Range works

If I am randomly deciding between 2 items, and use Random.Range

is
(not code just explanation)

rnd = Random.Range(1, 100);

if rnd <= 50, item1 is active,
if rnd >= 51, item2 is active,

going to return the exact same results as

rnd = Random.Range(1, 2);

if rnd = 1, item1 is active,
if rnd = 2, item2 is active,

Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).

``````rnd = Random.Range(1, 2);
``````

This will select only 1 not 2 because max is exclusive in your case.
if you want to select 2 states then use

``````rnd = Random.Range(1, 3);
``````

then will return either 1 or 2.
then decide in results what object will be active

`````` void Start()
{
switch (Random.Range(1, 3))
{
case 1:
//active 1
break;
case 2:
//active 2
break;
}
}
``````

if you use `rnd = Random.Range(1, 100);` then there are chances that function will return 50.

It depends, Random.Range has 2 overloaded methods. Random.Range(int, int) and Random.Range(float, float). In your case, you use int version. For int version, second parameter is for maximum value exclusive, which means for 50% probability you should write Random.Range(1,3).

In float version (not your case), it second parameter is inclusive, which mean for 50% probability need to set Random.Range(0f,1f) > 0.5f.

Links of doc: Unity - Scripting API: Random.Range

if the exclusivity mistakes are fixed

rnd = Random.Range(1, 101);
item 1 if rnd <= 50
item 2 if rnd >= 51

and

rnd = Random.Range(1, 3);
item 1 if rnd = 1
item 2 if rnd = 2

which is better to use, or does it matter?

I suck at this type of thing, and am trying to figure if the results would be exactly the same if I had set the random.range up right.

Nice, that’s what I was wondering, thank you.

Random.Range(0, 100) with a chance of 50 is exactly the same as Random.Range(0, 2).
Like in school, take everything you can outside the brackets.
You only want to use (0, 100) if your min chances are 1.