You can try combining a load from &FE44 with a circular table of random numbers, e.g.
Code:
.random
; increment and fetch random number table index
LDX randindex
INX
CPX #16
BCC wrapindex
LDX #0
.wrapindex
STX randindex
; fetch random number
LDA randtable,X
EOR &FE44
STA randtable,X
RTS
.randtable
; put 16 random numbers here
If you want to limit the number to between 0 and 2^n-1, that's easily done with an AND. If it's a non-power-of-two, e.g. between 0 and 23, unfortunately I can't think of an easier way than:
Code:
.try
JSR random
AND #31
CMP #24
BCS try