[RESOLVED] [2005] quick random numbers question (really easy!)
Hi guys,
I have a quick question on how random numbers work, if i say
Code:
Dim randN as New Random
Dim num as integer = 0
num = randN.Next(1, 2)
Will this return number 1 or 2, or will it always return 1, because i am using this in a project and want either 1 or 2 returned, but everytime i seem to run the application, it always uses 1?
Thanks in advance for any help
:afrog:
Re: [2005] quick random numbers question (really easy!)
you want this code
Code:
num = randN.Next(1, 3)
It may seem a bit odd at first, but the second number you pass to the Next() method is 1 more than the higest possible random you want.
Docs say:
MinValue
The inclusive lower bound of the random number returned. (meaning this number can be INCLUDED in the random value)
MaxValue
The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue. (meaning this number will be EXCLUDED when getting the next random number value)
Re: [2005] quick random numbers question (really easy!)
Thanks for the quick reply! Thats perfect, yeah it did confuse me a bit which is why i thought i'd check on here!
Thanks again
:thumb: