Search Unity

Random.Range never reach max?

Discussion in 'Scripting' started by Fraconte, Sep 2, 2014.

  1. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    What do you think would happen in this code?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RandomRangeTest : MonoBehaviour
    5. {
    6.     void Update ()
    7.     {
    8.         int test = Random.Range (0, 3);
    9.         if (test == 3)
    10.             print ("I was wrong");
    11.         else
    12.             print ("Why it never reachs 3?");
    13.     }
    14. }
    15.  
     
  2. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    GarthSmith likes this.
  3. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    Thx... I checked that but I didn't notice the difference between float and int. At least it's handy when you use it for index.