0

I was creating a typing app and I needed the program to randomly select one of the strings form my array without having the strings repeating themselves. Here is my code:

string[] words = {"banana", "stun", "consumer", "market", "programming", "lazy", "recruit" };

    Random rand = new Random();

then I have it called in my text box. thank you

  • if you select one how can it be a repeat? – pm100 Feb 17 '22 at 22:44
  • 1
    *"without having the strings repeating themselves"* - Randomize the array, then just select elements from it. – David Feb 17 '22 at 22:44
  • Maybe your issue is that you are creating a new Randow every time. If you do that in rapid succession you will get the same random number evry time. Instad create Random just once – pm100 Feb 17 '22 at 23:05
  • Look up "Shuffle Algorithm". What you want to do is _shuffle_ the deck of strings, and then pull them out one at a time (as @David says) – Flydog57 Feb 17 '22 at 23:17
  • @pm100 I have it called everytime you complete a word in the typing test – Joshua Peoples Feb 18 '22 at 01:09
  • I get what you want, sadly I cannot answer as the question is closed. I have voted to reopen, what you want is to have a function that returns a set of words in random order, one at a time – pm100 Feb 18 '22 at 01:16
  • actually just do the shuffle thats is linked above – pm100 Feb 18 '22 at 01:20

0 Answers0