I am working in a problem in which I have to print elements in array using random number logic.
The logic is that the elements of character should be printed randomly from the array. I have used random function for this.
The logic I implementing is that, I took the random number using function rand() and pick up the last two digit from it and with respect to them , I took the value from char array and print it down.
But the problem is that the array size is 0nly 40 and the number I get from generator some times greater than 40,so in this case repeated iterations will be there,which is not good practice.Also, I have to put the logic whether it from unit place or tens place.
Can anybody help me in implementing this.Actually I want to put the optimized solution.
The code is as follow:
int count =0,i,mul=0;
int seed = (int)time(NULL);
i = rand();
i = i/10;