At 03.41 1995-12-27 -0500, Shel Michaels wrote: >Hi all... > Anybody know of a good way to get a number out of a PIC which will be >randomly different each time it is powered up? I'm looking for one that >doesn't require operator input such as timing a button push, etc. Preferably >not involving any extra components such as measuring charge time for an RC >network. Use a linear feedback shift register with some good tap sequence. You may get every number in a say 15 bit register if you choose the tap sequence properly. One good sequence is: 15,1,0 which means that you should XOR the 15:th and the 1:st bit and put the result at the end of the "FIFO" register. +-|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|--- out | | | |---+--------------------------------+ This register will propagate through all 15-bit numbers until the initial seed will come back. (Store this register in EEPROM in case of power down) The sequence 63,1,0 works fine for 63-bit registers and there are a whole bunch of sequences, the only requirement is that the sequence must be primitive modulo 2. In an alternative representation, the sequence can be interpreted as a polynomial with degrees 63,1,0: x^63 + x + 1. This polynomial must be irreducible (cannot be factorized into two polynomials) in the same manner as with prime numbers. 15 = 5 * 3 but how about 17? 17 is a prime number and cannot be factorized. Oops, too much non-relevant theory here ... If you don't use the '84 or EEPROM:s? I guess you have to get some information from the world outside, e.g. measure the state of some independent 50-50 duty clock source, add a couple of these bits (modulo 2) and save the LSB as the first bit in your number. Do likewise for the other bits. If possible use more than one "random" source to collect bits. Real randomness is hard to produce but the above method should work quite well, the next is somewhat harder to implement in hardware.... I just feel like putting this text about rand tables in this reply as well, so enjoy: -------------------------------------------------- RAND Tables Back in 1955, when computers were still new, the Rand Corporation published a book that contained a million random digits. Their method is described in the book: "The random digits in the book were produced by rerandomization of a table generated by an electronic roulette wheel. Briefly, a random frequency pulse source providing on the average about 100,000 pulses per second, was gated about once per second by a constant frequency pulse, Pulse standardization circuits passed the pulses through a 5-place binary counter. In principle the machine was a 32-place roulette wheel which made, on the average, about 3000 revolutions per trial and produced one numher per second. A binary-to decimal converter was used which converted 20 of the 32 numbers (the other twelve were discarded) and retained only the final digit of two-digit numbers; this final digit was fed into an IBM punch to produce finally a punched card table of random digits," The book goes on to discuss the results of various randomness tests on the data It also suggests how to use the book to find a random number: "The lines of the digit table are numbered from 00000 to 19999. In any use of the table, one should first find a random starting position. A common procedure for doing this is to open the book to an unselected page of the digit table and blindly choose a five-digit number; this number with the first digit reduced modulo 2 determines the starting line; the two digits to the right of the initially selected five-digit number are reduced modulo 50 to determine the starting column in the starting line. To guard against the tendency of books to open repeatedly at the same page and the natural tendency of a person to choose a number toward the center of the pages every five-digit number used to determine a starting position should be marked and not used a second time for this purpose." -------------------------------------------------- -- Conny