I need to generate a binary file containing only unique random numbers, with single precision. The purpose is then to calculate the entropy of this file and use it with other datasets entropy to calculate a ratio entropy_file/entropy_randUnique. This value is named "randomness".
I can do this in python with double-precision numbers and inserting them into set()
, using struct.pack
like so:
numbers = set()
while len(numbers) < size:
numbers.add(struct.pack(precision,random.random()))
for num in numbers:
file.write(num)
but when I change to single precision I can't just change the pack method (that will produce a lot of the same numbers and the while will never end), and I can't generate single precision numbers with random
. I've looked into numpy
but the generator works the same way from what I understood.
How can I get 370914252 (this is my biggest test case) unique float32 inside a binary file, even if they're not random, I think that a shuffled sequence would suffice..