piclist 2002\08\12\205432a >
Thread: Random sequence
www.piclist.com/techref/microchip/math/index.htm?key=random
face picon face BY : Jinx email (remove spam text)



> I¹m doing led dies

As someone else suggested a fast-running clock will give you
random output on the dice. I've seen a couple of electronic
dice projects in magazines that do it this way. The dice are
driven 1 - 6 at high speed (no micro, just an oscillator) and it's
purely chance what number is showing when you push a button

However, you did also ask about external input. I've had to do this
very recently to generate large random numbers and used white
noise

http://home.clear.net.nz/pages/joecolquitt/white_noise.html

This little snippet of code may not make a lot of sense out of context
but what it basically does is to read the timer low byte after a random
delay (caused by noise transitions on a port pin). The timer low byte
read after this delay then becomes the random number used in the
rest of the code. It appears so far to produce unpredictable randomness

I'm pretty sure you don't need to go to these lengths as you're dealing
with a restricted range of numbers

;============================================

rndlo call    noise
         movf    tmr1l,w       ;get timer low byte after random delay
         movwf   lo

        btfss   high_eqlm    ;test addlow if hi=cnt2
        goto    rnd_th           ;else keep it

        movlw   0x01           ;comparison for range limit
        addwf   cnt1,w
        subwf   lo,w
        btfsc   carry
        goto    rndlo            ;re-generate until lo < cnt1+1

.......  rest of code
;-----------

noise movf   tmr1l,w       ;loop anywhere from 0x08 to 0x17 times
         andlw  0x0f
         addlw  0x08
         movwf  index
t_rnd btfss  noise         ;count noise L > H > L transitions
         goto   $-1
         nop
         btfsc  noise
         goto   $-1
         decfsz index,f
         goto   t_rnd
         return

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


<007901c24263$fae36fc0$639fa7cb@joe> QUOTED-PRINTABLE

See also: www.piclist.com/techref/microchip/math/index.htm?key=random
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Random sequence

month overview.

new search...