I'm pretty new to VB, so I'm starting off by making a simple program. I'm trying to simulate rolling some dice and calculating various results. My problem is this: sometimes, the number generated is zero. This plays havoc with the rest of the program.
I've defined a new function to make generating my random numbers easier.
- Code: Select all
Public Function Random(ByVal Low As Long, ByVal High As Long) As Integer
Random = CInt(Int((High - Low + 1) * Rnd()) + Low)
End Function
Then, whenever I want to "roll the dice," I just type something like...
- Code: Select all
someVar = Random(1, 6)
This sometimes spits out a zero. From my limited understanding of how Rnd() works, this shouldn't be happening. Can anyone help?
(And yes, I'm initializing Randomize() at the start of the program.)
EDIT--
I'm using VB 2008 Express.

