Shop OBEX P1 Docs P2 Docs Learn Events
Need Help generating Random number LIMIT — Parallax Forums

Need Help generating Random number LIMIT

mrdontaymrdontay Posts: 3
edited 2007-08-04 03:57 in BASIC Stamp
How do i generate a number between 1 and 6 . By default the RANDOM fuction in Pbasic generates a number between 0 and 65535 using a "seed" number as a starting point.



Here is the code I need to modify or if there is a better way please let me know. Thanks



result· VAR··· Word

Setup:

·· result = 1000···

Main

·· RANDOM result

·· DEBUG DEC ? result

·· GOTO MAIN

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-04 03:57
    Try "theNumber = result // 6 + 1"

    The modulus operator provides the remainder after division by 6 (in this case). That's between 0 and 5, so we add one.
Sign In or Register to comment.