I need to test the randomness of a Blum Blum Shub generator I built in Python, using the ENT randomness tests. I have a python array of pseudo random bits of form
[0, 1, 1, 1, 0, 0, 1, 0, 0, ...]
, and I need to write this sequence of bits into a binary file that I can then run through the ENT randomness test platform (ENT website linked here).
Would anyone be able to help me find a way to do this? I tried using the struct
package, but I do not think I am using it correctly: if p
is the bit array as shown above, I am writing to the file as follows using struct
:
f=open("myfile","wb")
myfmt='b'*len(p)
bin=struct.pack(myfmt,*p)
f.write(bin)
f.close()
Could anyone point out how to correctly do this? Further, if instead the array was not of 0, 1 values but instead composed of the pseudo random positive integers, what would be the correct way to write these to a file to test for randomness?