Skip to content
Advertisement

Tag: bit-manipulation

Randomly Generate bitstrings with fixed sum

I would like to generate a set of randomly generated bit strings with a certain length N, but I would like to ensure that the sum of each bit string adds up to a certain number, say $k$. How would I go about doing this in Python without generating all possible bit strings and removing ones that don’t add up

Advertisement