RANDOM and 12F683 - generates same values each time


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: RANDOM and 12F683 - generates same values each time

    Code:
    include "modedefs.bas" 
    DEFINE OSC 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 4 
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 1500
    DEFINE LCD_DATAUS 44
    ADCON1=%00000110 'CONFIGURE PORT A AS DIGITAL
    
    PIRVELI VAR BYTE   'CHARTVISAS BEEPEBIS RAODENOBA
    MEORE VAR BYTE      'CHARTVISAS LEDEBIS CIMCIMIS RAODENOBA
    MESAME VAR BYTE     'meore etapisatvis shemtxveviti ricxvi
    MEOTXE VAR BYTE     'MESAME ETAPIS SHEMTXVEVITI RICXVI
    DROEBITI VAR WORD   'DROEBITI SHEMTXVEVITIS GENERACIISATVIS
    DROEBITI2 VAR WORD
    DROEBITI3 VAR WORD
    MTVLELI VAR WORD    'VARIABLE FOR COUNTER
    bvar1 var byte
    bvar2 var byte
    ROM1    VAR BYTE
    ROM2    VAR BYTE
    ROM3    VAR BYTE
    ROM4    VAR BYTE
    
    'PRAVI VAR GPIO.0
    
    'DEFINITIONS
    TAVKA:
    DROEBITI2=0
    DROEBITI3=0
    DROEBITI=0
    READ 1,ROM1
    READ 2,ROM2
    READ 3,ROM3
    READ 4,ROM4
    
    
    
    GENERATE: 'CVLADEBIS GENERACIA
    RANDOM DROEBITI
    PIRVELI=(DROEBITI//6)+1
    RANDOM DROEBITI
    MEORE=(DROEBITI//6)+1
    RANDOM DROEBITI
    MESAME=(DROEBITI//6)+1
    RANDOM DROEBITI
    MEOTXE=(DROEBITI//6)+1
    
    lcdout $fe,$c0,"1=",#pirveli, "  2=",#meore, "  "
    pause 50
    goto generate
    end
    On each cycle run, it returns different results. With 12F683, results are fixed, does not changing, no matter how many times loop is run.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: RANDOM and 12F683 - generates same values each time

    I may be misunderstnading but previously you said that you needed some random numbers on power up. Now you're running the routine in a loop (at least that's how I understand it) - that's not the same thing. Each time thru the loop the seed will be what the last RANDOM statement generated. But when you start from scratch (ie power up) the seed will always be 0. As long as the seed is the same (ie 0 at power up) you'll get the same results - and I'll stick to that for a little while longer ;-)

    Run this on a 16F870 and on a 12F683
    Code:
    GENERATE: 'CVLADEBIS GENERACIA
      RANDOM DROEBITI
      PIRVELI=(DROEBITI//6)+1
      RANDOM DROEBITI
      MEORE=(DROEBITI//6)+1
      RANDOM DROEBITI
      MESAME=(DROEBITI//6)+1
      RANDOM DROEBITI
      MEOTXE=(DROEBITI//6)+1
    
      lcdout $fe,$c0,"1=",#pirveli, "  2=",#meore, "  "
      pause 50
    end
    Cycle the power and run it again. Does it really give you A) Random numbers on the 16F870 but not on the 12F683 and/or B) Different results on 16F870 compared to the 12F683?

    /Henrik.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,122


    Did you find this post helpful? Yes | No

    Default Re: RANDOM and 12F683 - generates same values each time

    Tested the above code. On power up, it gives 3 and 6 on 16f870 and 2 and 4 on 12f683, same results on each power up.

    however, if I place it in the loop, results on 16f870 are changing, while on 12f683 they remain 2 and 4.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: RANDOM and 12F683 - generates same values each time

    Hi,
    OK, the fact that you don't get the exact same sequence from the two devices could possibly (I don't know) come from the different instruction width (12 vs 14 bits) between the two. But why the 12F683 doesn't continue the sequence when the routine is looped is beyond me.

    /Henrik.

Similar Threads

  1. Adding values one at a time and sending them serially
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st August 2013, 14:56
  2. Why does this PBP statement post the wrong time values?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd November 2011, 03:10
  3. DS1904 RTC - How to Convert Binary Time into Real Time/Date?
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd December 2010, 10:45
  4. LCDOUT generates errors.
    By PICante in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th September 2009, 17:58
  5. Linx RF -> HSERIN time delay / time critical app...
    By batee in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th October 2004, 15:04

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