RANDOM - always the same result


Closed Thread
Results 1 to 9 of 9

Hybrid View

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

    Default RANDOM - always the same result

    Hello,

    I'm doing something so obviously wrong, I can't see the tree in the forest anymore.

    Code:
    rvalue VAR WORD
    random rvalue
    R_V0 = (RValue//4) + 1 ' Convert it to range 1-4
    if R_V0 = 1 then high led1
    if R_V0 = 2 then high led2
    if R_V0 = 3 then high led3
    if R_V0 = 4 then high led4
    The code above will always show "led3".

    What's wrong here?
    Roger

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    Hi,Flotul

    1) Read carefully the manual : there must be a SEED for the random function ... if always the same ... always the same result !!!

    2) a little SEARCH would be THE THING to do ... good surprise for you !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Got it working... but I don't know why

    Bonjour Alain,

    Thanks...

    I just found a way to make it work.

    I changed my code and put R_V0 = rvalue & $03. But, to be honest, I don't understand why it works now.

    Before opening this thread, I read lots of other threads about this subject. I've also been reading the Compiler's manual. I read this "Var is used both as the seed and to store the result" but my english is to poor and I don't understand the correct meaning of the word "seed" (graine - in french) here.

    Could you explain this command in other words please?
    Roger

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Kind of 'conjugaison du verbe voir => see, seed'.

    Qu'est-ce qui a déja été vue, sortie, choisi, sélectionné.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default Ben...

    j'ai l'air un peu c.. avec ma "graine"

    a) So, when the statement is RANDOM RandomVar, the "output" value will be stored in RandomVar, no?

    b) R_V0 = rvalue & $03 will keep only the 4 LSB of the result, no?

    c) still don't understand why my code in post#1 doesn't work. Must I specify it is in a loop? It is and doesn't work.
    Roger

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    j'ai l'air un peu c.. avec ma "graine"
    LMAO you don't want to know the meaning of the Quebec expression 'Graine'

    a) So, when the statement is RANDOM RandomVar, the "output" value will be stored in RandomVar, no?
    Indeed

    b) R_V0 = rvalue & $03 will keep only the 4 LSB of the result, no?
    Nope, 3=%00000011 so only the 2 LSBs

    c) still don't understand why my code in post#1 doesn't work. Must I specify it is in a loop? It is and doesn't work.
    I guess you should use something like
    rvalue=R_V0 before using Random again...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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