in reply to Re: Re: randomly choosing elements from an array
in thread randomly choosing elements from an array

What dws mean is:
  1. create an index array containing all valid index. For example, if you have a list of 5 words, then this index array world be (0,1,2,3,4).
  2. Shuffle this inddex array randomly, so it becomes something like (3,0,4,2,1). (I guess, the difficulty to you would be how to shuffle this array ;-)
  3. Now pick the words. For example, continue from step 2, say you want pick 2 words. As the first two elements of the shuffled index array is 3 and 0, so you just pick the words at index 3 and 0 of your word list.
  • Comment on Re: Re: Re: randomly choosing elements from an array

Replies are listed 'Best First'.
Re: Re: Re: Re: randomly choosing elements from an array
by sulfericacid (Deacon) on Mar 19, 2003 at 16:02 UTC
    Thanks so much for the explanation on how to do this. I surely don't know how to shuffle but now that I know the easiest way to get this done, shuffle shouldn't be so hard :)

    Thanks for your help!!

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid