Random Nums Problem

atesh

Freshman
Joined
Aug 2, 2003
Messages
41
Location
Washington State, USA
Visual Basic:
Dim GetRan As New Random
GetRan.Next(1, 50)

Why is it that this will never return the number 50? I thought the first number (in this case 1) is supposed to be the lowest possible number to return, and the second number (in this case 50) is supposed to be the highest possible number to return. But apparently, the highest number it can return is 1 - the second number (in this case 49).
 
Change the number to 51.

And also, it would be the second number minus 1. 1 minus the second number would be -49. :p
 
It won't go up to 50 because it's basically saying, give me a random number from 1 up to 50. If you returned a double value on random, you'd get something like 1 to 49.99999999. Since you're using integer values, it's 1 to 49.
 
Back
Top