def make_logical_imm(bit64):
    element_size = random.choice([2, 4, 8, 16, 32, 64] if bit64 else [2, 4, 8, 16, 32])
    ones = random.randrange(1, element_size)
    rotation = random.randrange(0, element_size)

    element = [0] * (element_size - ones) + [1] * ones
    l = element * ((64 if bit64 else 32) // element_size)
    rotated = l[rotation:] + l[:rotation]

    return int("".join(map(str, rotated)), 2)