> Folks > > I am new to this community and would like to ask if anyone has a routine > for a 16C84 to generate random numbers? > > thanks, marc bohlen > For a 16 bit pseudo-random number (2**16-1 states): random res 2; reserve space for number ... ; on power-up, initialize the number to any non-zero value movlw 1; movwf random+1; ... ; to get the next pseudo-random number clrf temp1; to make the next value movfw random; get high byte andlw 0xB4; isolate bits for exclusive or movwf temp2; loop: movfw temp2; addwf temp2,f; shift temp and set Z when done btfsc STATUS,C; check if next bit is set incfsz temp1,f; btfss STATUS,Z; check if temp2 is now zero goto loop; rrf temp1,f; get parity of random ^ 0xB4 into C rlf random+1,f; now shift random number to the left rlf random,f; ... Now if you initialize the random number to the same seed everytime, you will always get the same pattern of numbers out. So you might want to try using the value of a timer initially to seed the pseudo- random number generator, but make sure it is not zero. Dave Reinagel