; Random Number Generator
;
; This routine generates a 16 Bit Pseudo Sequence Random Generator
; It is based on Linear shift register feedback. The sequence
; is generated by (Q15 xorwf Q14 xorwf Q12 xorwf Q3 )
;
; The 16 bit random number is in location RandHi(high byte)
; & RandLo (low byte)
;
; Before calling this routine, make sure the initial values
; of RandHi & RandLo are NOT ZERO
; A good chiose of initial random number is 0x3045
;*******************************************************************
;
Random16
rlcf RandHi,W
xorwf RandHi,W
rlcf WREG, F ; carry bit = xorwf(Q15,14)
;
swapf RandHi, F
swapf RandLo,W
rlncf WREG, F
xorwf RandHi,W ; LSB = xorwf(Q12,Q3)
swapf RandHi, F
andlw 0x01
rlcf RandLo, F
xorwf RandLo, F
rlcf RandHi, F
return
;