I need to generate 500 numbers, 250 1s and 250 0s, randomly located. Below is what I do now. But it does not feel right while the output is correct.
trialNo=500
RandomSample@Flatten[Table[#, {trialNo/2}] & /@ {0, 1}]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d actually do something slightly different. Since you’re looking for a random permutation of
Flatten[{ConstantArray[0,250], ConstantArray[1,250]}], I’d generate the permutation and usePartto get the list you’re looking for. As follows,This isn’t operationally different than what you’re doing, but I think it captures mathematically what your trying to accomplish better.