I have an array of 27 elements, and I don’t want to generate all permutations of array (27!)
I need 5000 randomly choosed permutations, any tip will be useful…
I have an array of 27 elements, and I don’t want to generate all
Share
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.
To generate one permutation use
random.shuffleand store a copy of the result. Repeat this operation in a loop and each time check for duplicates (there probably won’t be any though). Once you have 5000 items in your result set, stop.To address the point in the comment, Python’s random module is based on the Mersenne Twister and has a period of
2**19937-1, which is considerably larger than27!so it should be suitable for your use.