RANDOM - always the same result


Results 1 to 9 of 9

Threaded View

  1. #9
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default PARALLAX - Basic Stamp explains clearly

    As often, I can find interresting information in the Basic Stamp's documentation.

    At least, at my level of comprehension, it is much more clear than the PBP Compiler's manual.

    Is someone else has (or had) the same problem as me, here is an extract of PARALLAX's BS2 documentation:
    RANDOM generates pseudo-random numbers ranging from 0 to 65535.
    They’re called “pseudo-random” because they appear random, but are
    generated by a logic operation that uses the initial value in Variable to "tap"
    into a sequence of 65535 essentially random numbers. If the same initial
    value, called the "seed", is always used, then the same sequence of
    numbers is generated
    .

    In applications requiring more apparent randomness, it's necessary to
    "seed" RANDOM with a more random value every time. For instance, in
    the demo program below, RANDOM is executed continuously (using the
    previous resulting number as the next seed value) while the program
    waits for the user to press a button. Since the user can’t control the timing
    of button presses very accurately, the results approach true randomness.

    Main:
    FOR trials = 1 TO 100 ' flip coin 100 times
    Hold:
    RANDOM flip ' randomize while waiting
    BUTTON Btin, 0, 250, 100, btnWrk, 0, Hold ' wait for button press
    IF (coin = 0) THEN ' 0 = heads, 1 = tails
    DEBUG CR, "Heads!"
    heads = heads + 1 ' increment heads counter
    ELSE
    DEBUG CR, "Tails..."
    tails = tails + 1 ' increment tails counter
    ENDIF
    NEXT

    PARALLAX "BASIC Stamp Syntax and Reference Manual Version 2.1
    NB: Forum Administrators - please let me know if reproducing this kind of information is not allowed.
    Last edited by flotulopex; - 18th March 2007 at 13:55.
    Roger

Similar Threads

  1. Strugling without floating point
    By pjsmith in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 27th March 2011, 06:29
  2. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 08:47
  3. 6 random numbers limiting to 49 ?????
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th June 2005, 23:27
  4. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  5. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts