Shop OBEX P1 Docs P2 Docs Learn Events
storing a randomly generate number in a variable — Parallax Forums

storing a randomly generate number in a variable

ArchiverArchiver Posts: 46,084
edited 2002-11-23 18:26 in General Discussion
Hi all, I have a set of different loops in my program(loop1: loop2: -
-- loop8[noparse]:)[/noparse], I generate two random numbers, I store them in two
variables called num1, numb2. now I want to use these random numbers
to determine which loop will be activated, but I am finding out that
I cannot have loopnum1, loopnum2. the program return num1 as
undefined variable, can anyne help me? by the way I am new to the
pbasic language.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-23 17:05
    At 03:48 PM 11/23/02 +0000, you wrote:
    >Hi all, I have a set of different loops in my program(loop1: loop2: -
    >-- loop8[noparse]:)[/noparse], I generate two random numbers, I store them in two
    >variables called num1, numb2. now I want to use these random numbers
    >to determine which loop will be activated, but I am finding out that
    >I cannot have loopnum1, loopnum2. the program return num1 as
    >undefined variable, can anyne help me? by the way I am new to the
    >pbasic language.
    It may well be helpful if you cut and pasted your program into a message.
    This way we can see exactly what you are attempting to do. This list does
    not accept attachments.


    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and
    >Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-23 18:26
    If I understand you correctly, you should be able to use BRANCH to call any
    of your "loops" with the random value generated elsewhere. Here's the idea:

    Main:
    RANDOM randWord
    rnd1 = rndWord.LowNib(0) * %0111
    BRANCH rnd1, [noparse][[/noparse]Loop1, Loop2, Loop3, .... ]
    GOTO Main

    Loop1:
    ' code here
    GOTO Main

    Loop2:
    ' code here
    GOTO Main


    -- Jon Williams
    -- Applications Engineer, Parallax


    In a message dated 11/23/02 9:49:26 AM Central Standard Time,
    konpen@y... writes:


    > Hi all, I have a set of different loops in my program(loop1: loop2: -
    > -- loop8[noparse]:)[/noparse], I generate two random numbers, I store them in two
    > variables called num1, numb2. now I want to use these random numbers
    > to determine which loop will be activated, but I am finding out that
    > I cannot have loopnum1, loopnum2. the program return num1 as
    > undefined variable, can anyne help me? by the way I am new to the
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.