I have a numeric vector of length x, all values in the vector are currently 0. I want it to randomly assign y of these values to equal 1, and x-y of these values to equal 0. Any fast way to do this? My best guess right now is to have a RNG assign each value to 0 or 1, sum up the string and, if the sum does not equal y, start all over again.
Can I use random.choice(vector,y) and then assign the elements that were picked to equal 1?