Shop OBEX P1 Docs P2 Docs Learn Events
a way to generate random word values between 1 and n — Parallax Forums

a way to generate random word values between 1 and n

youngdaveyoungdave Posts: 70
edited 2009-08-12 02:34 in Propeller 1
I’m looking for a way to generate random word values between 1 and n (a number definable by me). Is there a better way than simply selecting values between 1 and n from the output of the RealRandom.spin object. Does anyone have any ideas?
TIA David Young

Comments

  • heaterheater Posts: 3,370
    edited 2009-08-11 07:10
    Use the modulo operator on the output of real random.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • youngdaveyoungdave Posts: 70
    edited 2009-08-11 21:34
    Brilliant suggestion.
    Thanks David Young
  • RaymanRayman Posts: 14,845
    edited 2009-08-12 02:34
    You can use the "?" operator of Spin to generate the random numbers...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Sign In or Register to comment.