Random…. More like a scripted Sequence !!!


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Unhappy Re: Random…. More like a scripted Sequence !!!

    Further to this thread...

    Although using :-

    adcin ch,myword
    random myword

    I am using the same ADC port to create 2 random numbers....:-

    adcin 4,myword1
    random myword1

    adcin 4,myword2
    random myword2

    Altough the sequence is random..... I am getting repeats (the two myword results are the same)....!

    Is it doable to multiply/ divide/ add the myword by a number to change iton one of the words:-

    adcin 4,myword1
    myword1=myword1*7 ' (myword2=myword2*5 for second one)
    random myword1

    I have tried the above and differing variables of it ..... But I still get the repeating outputs. Channel 4 is the only ADC channel spare enough to be doing nothing.

    Thank you again for reading. Hope it makes sense

    Andy

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Random…. More like a scripted Sequence !!!

    If you have some user input on pic, you can use that for seed value by measuring time between button press and release. But again RANDOM just use some math and probably after some time repeat result.
    For dice I used this code:
    Main:
    For i = 1 to 6
    If button=pressed Then GoSub ShowResult
    Next i
    GOTO Main
    That is closest to random as you can get it. Result depending only on user button press. Variable will change value about 200 000 times in one second, so there is no way to repeat sequence...

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Random…. More like a scripted Sequence !!!

    Hi,
    If the ADC aproach isn't working then using one of the PICs timers in freerunning mode to provide the seed might do it. For this to work the execution of time between each instance of the random instruction must not be constant.

    /Henrik.

Similar Threads

  1. Replies: 13
    Last Post: - 5th September 2010, 02:55
  2. How to set sequence of interrupt for PIC
    By chai98a in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st June 2008, 12:17
  3. FOR sequence is skipped
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th August 2006, 03:35
  4. Installation sequence
    By Demon in forum General
    Replies: 23
    Last Post: - 11th July 2006, 04:56
  5. Switch Sequence
    By Tissy in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 13th February 2005, 21:36

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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