> To generate a dice roll, say a D6, arrange a counter and start it at 0, > > Then generate a bit (using the LFSR from my previous post), if it is one, > increment the counter, if it is 0 then leave the counter alone. Check the > counter is not greater then 5, if it is then reset it to zero. Do this many > times. Then use the number in the counter as your roll. It seems the problem comes down to generating a random number from 0 to N, where N+1 is not a power of 2. I have a routine that does this on a 16F876. If first finds the mask for all the bits in the number. In other words, it finds the smallest 2**K-1 that is greater than or equal to N. You now get a random binary number and AND this mask to it. If the result is greater than N, throw it out and try again. The worst case average is you have to throw out 1 of every 2 random numbers. The source code is in HAL_RAND.ASPIC at http://www.embedinc.com/pic/hal.htm. ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads