def _roll_random(n):
bits = util.bit_length(n - <NUM_LIT:1>)<EOL>byte_count = (bits + <NUM_LIT:7>) // <NUM_LIT:8><EOL>hbyte_mask = pow(<NUM_LIT:2>, bits % <NUM_LIT:8>) - <NUM_LIT:1><EOL>while True:<EOL><INDENT>x = os.urandom(byte_count)<EOL>if hbyte_mask > <NUM_LIT:0>:<EOL><INDENT>x = byte_mask(x[<NUM_LIT:0>], hbyte_mask) + x[<NUM_LIT:1>:]<EOL><DEDENT>num = util.inflate_long(x, <NUM_LIT:1>)<EOL>if num < n:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return num<EOL>
returns a random # from 0 to N-1