Mike W wrote: > I could use a routine to produce a random number between 0 and 45 > decimal .... the timer is [already] being used, but perhaps it > could [also] be used as a seed [for the random-number generator] Mike: If you don't mind that the distribution of random numbers will be VERY skewed toward the low end of your [0-45] range, or that this routine takes a non-constant time to execute, you could do this: LOOP: MOVF TMR0,W ANDLW 01111111B ADDLW -46 BC LOOP ADDLW 46 After executing the fragment above, W will contain a number in the range [0-45]. To make the distribution a little better, change the first line from a MOVF to a SWAPF: LOOP: SWAPF TMR0,W ANDLW 01111111B ADDLW -46 BC LOOP ADDLW 46 If you want numbers that are distributed even more evenly, replace the first line with one of the simple random-number-generator routines from my web page. See: http://home.netcom.com/~fastfwd/answers.html#PIC00075 For example: MOVLW [any non-zero value] ;Seed the generator MOVWF RANDOM ;(you only need to do ;this once). .... LOOP: MOVLW 01DH ;(This routine was CLRC ;written by Marv RLF RANDOM ;Isaacman). SKPNC ; XORWF RANDOM ; MOVF RANDOM,W ANDLW 01111111B ADDLW -46 BC LOOP ADDLW 46 Keep in mind that that last routine will produce a repeating sequence of random numbers; if you don't want the pattern to repeat deterministically, re-seed the generator periodically with the TMR0 value. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - San Diego, California === http://www.geocities.com/SiliconValley/2499