Problem: Generate large binary strings (length 2000+). Do it quickly, as this generateRandom() function will be called 300,000 times in the algorithm.
Attempted Solutions: Generate 3 or 4 binary numbers and append them all together 500 times. This is awfully slow.
Make a single call to random.random() and multiply it by a huge number. Convert to binary once and be done. This works for smaller numbers, but because the binary string must be a certain length, the number to convert to binary must be truly enormous (2 ** len(binString)).
Current Code (works for smaller numbers):
binaryRepresentation = ''
binaryRepresentation += bin(int(random.random() * (2 ** binLength)))[2:].zfill(binLength)
Error that I need help fixing: This call throws a "long int too large to convert to float" with the large numbers. Is there a way to make the overall algorithm more efficient or to make this large number convert-able to a float?
Thank you!