Shop OBEX P1 Docs P2 Docs Learn Events
Random Number Generation — Parallax Forums

Random Number Generation

CreativeCreative Posts: 11
edited 2005-10-05 14:42 in BASIC Stamp
I have tried using the random number providing the 'seed' value, but i have no idea what it means even after reading through the help topics. I tried to output a random number that ranges from 1 to 9 but with the 'seed' statement, the output number becomes huge etc. 55246, 11253.. without the 'seed' statement, i will get a number repetitively. Please give me some guidance on this problem. Thanks! lol.gif

Post Edited By Moderator (Chris Savage (Parallax)) : 10/5/2005 2:02:19 PM GMT

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-10-05 14:42
    Ok, the command RANDOM generates 16 bit psuedo-random numbers, it is psuedo (meaning close but not quite, literally "false"). For each seed provided to the RANDOM command, it generates the exact same list, every time, so the seed used sets which list it pulls numbers from, so to get random numbers you need to provide a unique seed value, the Stampworks documentation discloses how to use a button that you press to generate the seed. The number you get back will be between 0 and 216-1, so to get a random number between 1 and 9, get a random number (we'll call it RND) and do:

    RND//9 + 1

    what this does is takes the random number, divides it by 9 and returns the remainder (resulting in a number between 0 and 8) then you add one to shift the number to be between 1 and 9.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
Sign In or Register to comment.