+ 3

Random.Range

if i set mindrop to 0 and maxdrop to 3. if i do. int dropamount = random.range(mindrop,maxdrop) i always get 0 1 or 2 as result. what am i doing wrong

13th Mar 2018, 8:56 PM
Roel Bekker
Roel Bekker - avatar
4 Answers
+ 4
maxdrop is exclusive. https://docs.unity3d.com/ScriptReference/Random.Range.html public static int Range(int min, int max); Description Returns a random integer number between min [inclusive] and max [exclusive] (Read Only). Note that max is exclusive, so using Random.Range( 0, 10 ) will return values between 0 and 9. If max equals min, min will be returned.
13th Mar 2018, 9:05 PM
sneeze
sneeze - avatar
+ 7
If you are looking for a whole number from 0 to 3 (inclusive), increase the maxDrop by 1. Random.Range(minDrop, maxDrop + 1); As @sneeze explains, you need to do this because maxDrop is exclusive.
13th Mar 2018, 9:08 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
cheers both
13th Mar 2018, 9:21 PM
Roel Bekker
Roel Bekker - avatar
0
try this, int dropamount=random.range(mindrop,maxdrop+1);
16th Mar 2018, 2:13 AM
Mohd Zaki
Mohd Zaki - avatar