I wish to generate a random binary string of length N such that each of the possible 2^N strings is uniformly randomly chosen. Note that choosing 1 or 0 with equal probability to build a string doesn't work because with high probability the string contains equal numbers of 0s and 1s, and so such strings are generated with higher probability. Another way is to generate the list of all 2^N strings and then choose one of them. However, this quickly becomes impractical when N is even 30. I need to work with N = 500. How can I achieve this? If python has an in-built function for such thing, it would be even better.
Edit Clearly I posed a wrong question; apologies. What I wanted was a uniform distribution over the number of 1s in the string. So the string with just two 1s should be as probable as the string with all 1s. I could achieve this though.