Get ‘n’ random string from a Arraylist of string. Where n= number of string I want from the list it can be 1,2,3….? Suppose that I have Array list of N Strings if I want to choose Random four strings without repetition. How can I do it? The code should be in C#. Though I have done this, but What is the best way?
Share
Try this:
To keep each chosen string unique (prevent duplicates) I remove it from the source list as it is used. You should also do a
myList = myList.Distinct()before using the list, to make sure you don’t have duplicates in it to begin with.