in reply to randomly choosing elements from an array

There are different ways to do this.

One way is to have another array to remember which word has already been used (logically this is a bit mask), so you would not pick a used word twice (assume this is one of your requirement).

  1. For the first word, you just generate a random number within the range of array index, and pick the word at that index. Also mark it as used.
  2. Start from the second word, you generate a random number r first, if the word at index r is not used, pick it, and mark as used; if it is already used, check whether r + 1 is used, this goes on and on, until you find an unused one. Imaging the array as a ring, when you reach the end, go back to the beginning.
  • Comment on Re: randomly choosing elements from an array