added rand_bits function