count = 0
while count < n:
    bits = random.getrandbits(32)
value = struct.unpack('f', struct.pack('I', bits))[0]
if not math.isinf(value) and not math.isnan(value):
    index = bits // 8
mask = 1 << (bits & 7)
if used[index] & mask == 0:
    yield value
used[index] |= mask
count += 1
for num in random_unique_floats(size):
    file.write(struct.pack('f', num))
Generate large number of unique random float32 numbers