Currently, I have this:
Random random = new
random.Next(1, strings.Items.Count);
strings.Select();
strings.SelectedItem = strings.Items[Convert.ToInt32(random)];
var str = strings.SelectedItem;
if (str == "stuff")
{
//Here
}
It doens’t give any errors in the output, but it won’t run when I test it. I get an InvalidCastException, saying it was unable to cast an object of type System.Random to the type System.IConvertible.

What does this error mean, and how can I fix it?
Your original code shouldn’t compile (You missed
new Random();on the first line). It should be:You are getting the exception on following line, which tries to convert
randomobject to the int, that you can’t do and that is why you are getting the exception.It is wrong to index the
string.Itemsbased on therandomobject. It should be the random number returned by therandomobject, not the object itself.