Chen Xiao Fan wrote: >Sorry but which LFSR? The simple LFSR in the PIClist >archive does not seem to do this. > >LFSR: RLF RANDOM,W > RLF RANDOM,W > BTFSC RANDOM,4 > XORLW 1 > BTFSC RANDOM,5 > XORLW 1 > BTFSC RANDOM,3 > XORLW 1 > MOVWF RANDOM > RETLW 0 > >Regards, >Xiaofan > > Yes it does. You shift the random number to the left. Then you XOR the first bit depending on the other bits. So only the first bit gets changed. You will need to run through 3 times for 0-7, and 5 times for 0-31. David >-----Original Message----- >From: Wouter van Ooijen [mailto:wouter@voti.nl] >Sent: Thursday, June 23, 2005 4:57 PM >To: 'Microcontroller discussion list - Public.' >Subject: RE: [PIC] Simple pseudo random code generation > > > > >>Are there any simple code to generate arbitrary pseudo >>random number (<=8-bit)? >> >> > >The common LFSR pseudo-random generators in fact generate one bit per >step. Just take the number of bits you need. > >Wouter van Ooijen > >-- ------------------------------------------- >Van Ooijen Technische Informatica: www.voti.nl >consultancy, development, PICmicro products >docent Hogeschool van Utrecht: www.voti.nl/hvu > > > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist