|
-
Aug 20th, 2012, 03:35 AM
#3
Re: Random Numbers The Same
 Originally Posted by dday9
Would this suffice?
Code:
Public Function randomNumber(ByVal low As Integer, ByVal high As Integer) As Integer
Dim r As New Random
randomNumber = r.Next(low, high)
Return randomNumber
End Function
Don't do this. This is wrong. Do not construct the Random instance in the function. Your application should only ever create one Random instance and all places that need to use it should be passed a reference. With the above function, if it is called twice in succession it will return the same number, as both calls will seed the Random with the same value.
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
|