Jump to content

Photo

Best way to get a random number that is either -1 or 1


2 replies to this topic

#1 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,789 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Sep 4, 2010 5:09 AM

Is this the best way to get a random number that is either -1 or 1?

a = (255+(rand&1) | %00000001)


Thanks.

#2 Crazyace OFFLINE  

Crazyace

    Stargunner

  • 1,035 posts
  • Location:London / HK / Tokyo / San Fransisco

Posted Sat Sep 4, 2010 6:46 AM

a = 255+(rand&2)

#3 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • Topic Starter
  • 28,789 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat Sep 4, 2010 6:59 AM

a = 255+(rand&2)

Thanks. I've been blocking out anything besides 1, 3, 7, 15, 31, and so on for months, so I automatically ignored the other numbers. I knew there had to be a better way.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users