Thanks to Wouter, Adam, Peter. Olin: Working with Relocatable code would be a nice exercise since I don't used to. I'm afraid of the overhead, but I think is the most useful way. I suspect you've used the timer + fixed tables to get an even random numbers distribution. Nice, Thanks Bob: > val = PRNG(7); // start with a pin in 0..7 > for (;;) > { > val = (val + 1 + PRNG(6)) & 7; > } Yes, the solution is to "memorize" the previous value, which is more pseudo than random, but it works just fine. Thanks Here is where I've arrived, thanks to everyone. CBLOCK 0x0C RANDOM TIMES SALIDA ENDC ORG 0X000 GOTO INICIO ;...... INICIO MOVLW 0X01 ;Seed MOVWF RANDOM ;...... Randomize ;Main loop CALL LFSR ;Get the random MOVFW SALIDA ; GOTO Randomize ; ;***************************************** ;PRNG 8 bits ;by Nikolai Golovchenko ;Seed RANDOM with a number different to 0 ;during initialization. ;This code gives less sequential repetitions ;at edges (0 to 32, 224 to 255) ;than Andrew Warren's LFSR: CLRC RLF RANDOM, 1 SWAPF RANDOM, 0 ANDLW 0XE0 RRF RANDOM, 1 ADDWF RANDOM, 0 ADDWF RANDOM, 0 ADDWF RANDOM, 0 SUBLW 0X35 MOVWF RANDOM ;**************************** ;0-255 to 0-7 Converter MOVFW RANDOM MOVWF SALIDA BCF STATUS,C ;Division by 32 RRF SALIDA,F ; BCF STATUS,C ; RRF SALIDA,F ; BCF STATUS,C ; RRF SALIDA,F ; BCF STATUS,C ; RRF SALIDA,F ; BCF STATUS,C ;Salida has now the value RRF SALIDA,F ;the random number ;********************************* ;This is the mask routine ;by Mike Keitz. Converts 3 bits number ;to a 8 bit mask. MOVFW SALIDA ; ANDLW B'00000011'; MOVWF SALIDA ; INCF SALIDA, W ;THE 4-BIT CONVERTER BTFSC SALIDA, 1 ; IORWF SALIDA, F ; INCF SALIDA, F ; BTFSC RANDOM, 2 ;IS IT HIGH 4 BITS? SWAPF SALIDA, F ;Now Salida is MOVFW SALIDA ;80 or 40 or 20 or 10 ;08 or 04 or 02 or 01 ;*************************** ;If output is equal to the last value ;rotate it one more time ;if is zero one time again ;so output is never repeated XORWF TIMES,W ;Compare to previous BNZ NONEQUAL ;If is not necessary BCF STATUS,C ;jump... RRF SALIDA,F ;Change result... TSTF SALIDA ;Zero is not allowed BNZ NONEQUAL ; BSF STATUS,C ; RRF SALIDA,F ;Change result... NONEQUAL MOVFW SALIDA ;...and save it. MOVWF TIMES RETLW 0 END Ahora podis usar Yahoo! Messenger desde tu celular. Aprendi csmo hacerlo en Yahoo! Msvil: http://ar.mobile.yahoo.com/sms.html -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads