|
-
Apr 28th, 2008, 10:11 AM
#1
Thread Starter
Fanatic Member
[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
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Apr 28th, 2008, 10:15 AM
#2
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)
-
Apr 28th, 2008, 10:17 AM
#3
Thread Starter
Fanatic Member
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
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|