Author Topic: Random Number  (Read 2169 times)

0 Members and 1 Guest are viewing this topic.

Offline Electricity440

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Random Number
« on: April 18, 2013, 08:40:51 pm »
How can I generate a random integer from 0 to 36 and store it to a variable in axe?  ???

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Random Number
« Reply #1 on: April 18, 2013, 09:02:03 pm »
The command 'rand' generates a random number from 0 to 65535.  To restrict that range to a smaller range, you can use the modular arithmetic operator ^ like so: rand^37.  This divides the random number by 37 and returns the remainder.  By the nature of the remainder, its range is from 0 to N-1 when you divide by N, so this function returns your desired number from 0 to 36. 

Offline Electricity440

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
    • View Profile
Re: Random Number
« Reply #2 on: April 18, 2013, 09:37:20 pm »
 ok. thanks :hyper: