Pick Random String From Array
Posted
by
atrljoe
on Stack Overflow
See other posts from Stack Overflow
or by atrljoe
Published on 2011-07-14T14:49:58Z
Indexed on
2012/11/11
5:01 UTC
Read the original article
Hit count: 159
How do I go about picking a random string from my array but not picking the same one twice.
string[] names = { "image1.png", "image2.png", "image3.png", "image4.png", "image5.png" };
Is this possible? I was thinking about using
return strings[random.Next(strings.Length)];
But this has the possibility of returning the same string twice. Or am I wrong about this? Should I be using something else like a List
to accomplish this. Any feedback is welcome.
© Stack Overflow or respective owner