Shop OBEX P1 Docs P2 Docs Learn Events
RANDOM Command - formula — Parallax Forums

RANDOM Command - formula

Oxalium7Oxalium7 Posts: 5
edited 2009-05-01 23:31 in BASIC Stamp
Does anyone know the exact formula used to generate the sequence of 16-bit pseudo-random numbers that RANDOM BASIC command generates? I need to create a PRNG (pseudo-random number generator) app on a PC that generates PRNs like the Stamp RANDOM command.

Project Scenario:

Stamp-based product that user pays upfront for fixed "usage" time slot. When payment is confirmed, user is given an "unlock" number. When time is up, user is again prompted for an unlock number. After user pays another fee, they will be given the next unlock number. This new number is generated internally with the Stamp BASIC RANDOM command.

The user is provided with the unlock numbers by customer service who use a PC app that generates the PRNs.

I should also mention that the first unlock number is stored in the Stamp-based product before it is shipped to the customer.

Comments

  • icepuckicepuck Posts: 466
    edited 2009-04-25 00:01
    The programing language that you use will determine how you generate the random numbers..
    In VB2008 express you would use the Randomize() first some were in the Form_Load function and then Rnd functions in your formula.
    -dan
  • Oxalium7Oxalium7 Posts: 5
    edited 2009-04-27 19:21
    What I need to know is the pseudo-random number generator equation that Stamp BASIC uses internally so that I can implement it in any language and any platform. If I'm going to use the RANDOM function on the STAMP, I need to exactly match the number that it generates given a specific "seed". There is no assurance that the PRNG functions in VB2008 and other languages generate the same numbers in the same order as the RANDOM command in Stamp BASIC. They probably use a different generator equation.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-04-27 22:47
    There are only 65535 or 65536 numbers in the sequence before it repeats. Why not just output the entire sequence and store it in your PC?

    -Phil
  • Oxalium7Oxalium7 Posts: 5
    edited 2009-05-01 23:31
    To Phil Pilgrim ...

    If space is not at a premium, using 65536 16-bit values would be fine ... as on a PC. The current pseudo-random number would be an index into the 65536-element table where the next pseudo-random number in the sequence would be found.

    Some other systems with space constraints would probably have to use a PRNG rather than a table. Also, if one went to 32-bit or 64-bit based sequences ...

    If I needed to quickly change the pseudo-random number generator parameters, I may not want to have to bother having to generate a table every time - I would just change the few parameters that control the PRNG

    I just thought that someone out there might know what the Stamp BASICs PRNG parameters were.
Sign In or Register to comment.