create a set_rand_bitmask function and use instead of open-coding.