1 < x < 64
0 <= x < Upper_Limit
TRnd!(2,18)
1.99999
TRnd!(2,19)
2
SETPIN 1,DIN
FUNCTION TRnd!(x AS FLOAT,bits AS INTEGER) LOCAL INTEGER n,t,b b=Max(Min(bits,63),1) ' constrain bits to 1-63 FOR n=1 TO b t=(t<<1) + PIN(1) NEXT TRnd!=(1/(2^b)*t)*x ' the returned value can never be x but might be very close END FUNCTION