Quote:code that prints random contents The question is code should print distinct array contents but the code here prints same word twice sometimes
That's what random
means - the next number takes no notice of the previous sequence of numbers and selects a value at random from the total space. That means that it's quite possible to get a number of identical values in a row, especially in small phase spaces. Since you have only 5 items, the odds of getting two identical values in a row are 1/5, but it's quite possible to get 100 "My" indexes in a row, just as you can get 20 "black" calls in roulette (so the "double each time you lose" strategy can get very, very expensive quickly!)
If you want "random but no repeats", you need to copy the input array, scramble it by swapping random elements, then pull them out one by one until there are none left. You then set up a new array using all values except the last used, and scramble that and repeat.