-
Create an instance of
Random
class somewhere. Note that it’s pretty important not to create a new instance each time you need a random number. You should reuse the old instance to achieve uniformity in the generated numbers. You can have astatic
field somewhere (be careful about thread safety issues):static Random rnd = new Random();
-
Ask the
Random
instance to give you a random number with the maximum of the number of items in theArrayList
:int r = rnd.Next(list.Count);
-
Display the string:
MessageBox.Show((string)list[r]);