If you want a random binary sequence, then it's probably the quickest way to create a random integer in the corresponding range:
import random s = random.randint(0, 2**10000 - 1)
After that, it really depends on what you want to do with your binary sequence. You can request individual bits using bitwise operations:
s & (1 << x)
or you can use a library, such as bitarray or bitstring , if you want to check, set up a section, etc. simpler:
from bitstring import BitArray b = BitArray(uint=s, length=10000) p, = b.find('0b000000') if b[99]: b[100] = False ...
Scott griffiths
source share