Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that produces ten random permutations of the numbers 1 to 10. To

ID: 3638690 • Letter: W

Question

Write a program that produces ten random permutations of the numbers 1 to 10. To generate a random permutation, you need to fill a vector with the numbers 1 to 10 so that no two entries of the vector have the same contents. You could do it by brute force, by calling rand_int until it produces a value that is not yet in the vector. Instead, you should implement a smart method.
Make a second array and fill it with the numbers 1 to 10. Then pick one of those at random, remove it, and append it to the permutation vector.
Repeat ten times.

Explanation / Answer

#include #include #include #include #include #include using namespace std; bool random_compare(int a, int b) { return (rand() % 2)==0?-1:1; } int main() { srand(time(NULL)); vector v,p; for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote