randRange( 0, 255)

Express the decimal number Dec in binary notation.

Dec.toString(2)

Find the largest power of 2 that will go into Dec and put a '1' in its place.

Subtract the largest power of 2 that will go into Dec giving a remainder.

Find the largest power of 2 that will go into the remainder and put a '1' in its place.

Continue dividing, taking the remainder, until you get to the ones place (2 to the 0 power).

Add up all the powers of 2 that have a 1 in their place.

The answer is Dec.toString(2)