Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Random.randomBoolean function!

Discussion in 'Wish List' started by cupsster, Mar 25, 2011.

  1. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    Code (csharp):
    1. function randomBoolean ():boolean
    2. {
    3.     if (Random.value >= 0.5)
    4.     {
    5.         return true;
    6.     }
    7.     return false;
    8. }
    Return : boolean [true or false] cmon guys! Why it's not already there?.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Well, you wrote it, so now you have it. Problem solved. Usually the wish list is for things that are hard/impossible to add yourself.

    --Eric
     
  3. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    This is hardly a commonly requested feature nor difficult to program?
     
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Even shorter. :)

    return (Random.value > 0.5f);
     
  5. GodModeTech

    GodModeTech

    Joined:
    Jun 21, 2010
    Posts:
    66
    It think this will perform better:
    return (Random.Range(0, 2) == 1);
     
    SaSha_K and McGravity like this.
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It performs somewhat worse than Random.value > .5, actually.

    --Eric