How do I generate a list of length N with random 0 and 1 values , but with a given number of 1\'s put randomly in the list.
For example, I want a list of 10
You can make the list have the right number of 0's and 1's pretty easily
data = [0] * 3 + [1] * 7
and then use random.shuffle to make their positions within the list random
from random import shuffle shuffle(data) print data
[1, 1, 0, 1, 1, 0, 0, 1, 1, 1]