Algoritmo de aleatoriedad para PIC 16F84

Hola, estoy tratando de hacer un juego, pero tengo un poco de problemas para generar una aleatoriedad con numeros de 1 al 4, he hecho un, pero no me esta funcionando bien. Espero y alguien pueda ayudarme. Lo estoy haciendo para el PIC 16f84 y en ASM.

Gracias
Saludos desde Morelos, Mex.
 
Puedes hechar a andar el temporizador indefinidamente, deshabilitando su interrupción, y cada vez q necesites un número aleatorio, coges solo los 2 bits menos significativos del mismo, ahi tienes un numero aleatorio de 0 a 3, le sumas 1 y ahi tienes un numero aleatorio de 1 a 4 :D
Espero te sirva. Salu2:

BRAULIO
 
:LOL: aka tenes una forma sencilla de hacer numeros pseudo aleatorios... jojojo http://members.cox.net/berniekm/tricks.html
que lo disfrutes loco... jojojo


Better, faster, random numbers

Many random number generators are software versions of the hardware shift register feedback circuit. Two problems with this approach are that this operation is usually clumsy in software and the results have some noticeable patterns.

Some time ago, I don't remember just when, I came up with the Chop Suey Machine which works as follows:

Start with a set of memory locations (any size will do). Add the first value to the second one and store it in the second one. Now take the result and add it to the third one and store it there. Continue for as many locations as you like. Finally, add to the 1st byte and swap nibbles.
A three byte implementation in PIC code looks like this....

Código:
chop    movf    val1,w     ;get the 1st
        addwf   val2,w     ;add the 2nd
        movwf   val2       ;store the 2nd
        addwf   val3,w     ;add the 3rd & store
        movwf   val3       ;back in 3rd
        addwf   val1       ;add back to 1st
        swapf   val1       ;swap nibbles
        movf    val1,w     ;return one byte
        ret

An initial state of zero's in all locations results in zero's being output. Seed at least one location with a non zero value to start. Adding additional locations greatly increases the length of the series while adding very little overhead (2 instructions each). There is no guarantee of producing a maximum length sequence with this little ha.ck. You can't even guarantee the sequence length. Like may random generators, sequence length may depend on the initial values.
 
Atrás
Arriba