Is there a more efficient way to generate a 10 kBit (10,000 bits) random binary sequence in Python than appending 0s and 1s in a loop?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want a random binary sequence then it’s probably quickest just to generate a random integer in the appropriate range:
After this it really depends on what you want to do with your binary sequence. You can query individual bits using bitwise operations:
or you could use a library like bitarray or bitstring if you want to make checking, setting slicing etc. easier: