Search Unity

Random doesn't work

Discussion in 'Scripting' started by AAppDev, Aug 31, 2015.

  1. AAppDev

    AAppDev

    Joined:
    Aug 21, 2015
    Posts:
    17
    Hi i m using this Integer but he's returning 2 EVERY time :


    Code (CSharp):
    1. int jumpOrSlide = Random.Range(1,2);
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    int random is maximum exclusive. I would have thought that returned 1 every time.

    either way, increase the maximum value
     
    AAppDev, Kiwasi and tedthebug like this.
  3. AAppDev

    AAppDev

    Joined:
    Aug 21, 2015
    Posts:
    17
    Oh yes sorry I meant 1 is returning every time.

    I Increased the max value to 3 and now its working thank you !
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570

    To clarify in case you weren't sure, what JamesLeeNZ is saying is that random.range picks a number from (& including) the first number up to (but excluding) the second number. In your case it would be picking a number from 1 to 1.
     
    AAppDev likes this.
  5. AAppDev

    AAppDev

    Joined:
    Aug 21, 2015
    Posts:
    17
    Ok Thank you :D