Shop OBEX P1 Docs P2 Docs Learn Events
generate Random number — Parallax Forums

generate Random number

JohnnyfumiJohnnyfumi Posts: 14
edited 2008-05-14 17:49 in Propeller 1
Hy guys,
i have a simple question. Is it already exists a methods that can generate random numember given a fixed interval?
thank you so much

Johnny

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-14 17:23
    Look at the description of the "?" operator. This uses a linear feedback shift register to transform a 32 bit number to another 32 bit number in a pseudo-random fashion. You can then modify these numbers to get any interval you want. For example, you can use the modulus operator "//" to get pseudo-random numbers in the interval 0-n given a 32 bit pseudo-random number.
  • RaymanRayman Posts: 14,162
    edited 2008-05-14 17:49
    For the Ladder game that I just posted, I used this. Also, I used CNT to seed this generator when the user hits the "P" for play button.
Sign In or Register to comment.