more random number questions

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Saskatchewan Canada

    Question more random number questions

    I want to generate a random number between 0 and 15, but never had the same number come up twice in a row.

    I considered it like this:

    <b>random rand</b> ' generate the random number
    <b>num = rand & $000F</b> ' grab that last 4 bits of the number
    <b>if num = last then start</b> ' compare the number to the previously stored number and if it is the same do it again
    <b>last = num</b> ' store the number to compare next time

    This seems like it should work, but it's not working for me. I am still getting duplicate consecutive random numbers. Is it because I am using a word to store four bits and if that is the case, what is the proper syntax to compare just 0 to 15 on those words?



  2. #2
    Join Date
    Nov 2004
    Saskatchewan Canada


    Oops. I think the problem here was more physical than coding. With all the chip removal and installing I bumped a LED lose so with that back in place and careful watching it looks like there are no duplicate numbers back to back.


Similar Threads

  1. Questions on random numbers and multiplexing LEDs
    By AaronM in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th June 2009, 05:22
  2. Random number seed
    By kwelna in forum mel PIC BASIC
    Replies: 10
    Last Post: - 1st February 2007, 18:33
  3. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 18:50
  4. Newbie has some questions
    By bartman in forum General
    Replies: 43
    Last Post: - 5th October 2005, 17:51
  5. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 18:39

Posting Permissions

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