I want to make a list of x zeroes and y ones in random locations. It feels like this should be doable in Mathematica in a very few characters, but my solution (which works perfectly) is relatively verbose.
I'm here using 0 and 1 rather than False and True.
exactlyNOnes[n_Integer, outOf_Integer] := Module[{list, rands},
list = Table[0, outOf];
While[Total[list] < n,
list = ReplacePart[list, RandomInteger[outOf - 1] + 1 -> 1]];
list
];
I'm curious to know how wiser people would solve this.
RandomSample
, something like:RandomSample @ Join[ConstantArray[1, n], ConstantArray[0, m]]
. $\endgroup$