I want to generate numbers between range of 1 to n to create test cases for my program. So i created an array of size n and then stored it in array then usedrandom_shuffle
But it's actually not random it always gives same series of number. it changes series like after 3 or 4 shuffling.
So is there any better way to do it. My basic problem is just to create a series of number from [1, n] in any random manner.
int n = 9;
int arr[9] = {1,2,3,4,5,6,7,8,9};
int k = 2;
while(k--)
random_shuffle(arr, arr+ n);
for(auto x :arr)
cout << x <<" ";
Output : 5 4 8 9 1 6 3 2 7
So for either k = 1 or k = 2 it gives same output.