Hmm. It appears to be fixed. I don't think the problem was with generating the random number after all. I was using images of each side of the die, instead of just sticking the numbers onscreen. I stored the locations of the images in an array, and then used the random number to decide which image to use. Like this...
Code:
dim dice(5) as image 'assigned image locations on form load
Public Function Random(ByVal Low As Integer, ByVal High As Integer) As Integer
Random = CInt(Int((High - Low + 1) * Rnd()) + Low)
End Function
'more stuff here
someVar = Random(1, 6)
picturebox.Image = dice(someVar - 1)
The image paths are stored in the array in order. So the first is 1, the second is 2, and so on.
My thinking was that if the number generated was a 4, all I had to do was subtract 1 to get the index of the proper image in the array. Apparently that doesn't work. I kept getting "array out of bounds" exceptions. When I looked at the error details, it said that
someVar had a value of zero. So subtracting 1 would have the program trying to access
dice(-1), which of course doesn't exist. I changed the code to the following, and no more errors:
Code:
someVar = Random(0, 5)
picturebox.Image = dice(someVar)
I don't understand one thing. Shouldn't I be able to use a simple expression such as
(someVar - 1) as the index of an array? Did I just apply it incorrectly?