I have this code to pick a random number Between X and Y
X = Minimum Number
Y = Maximum Number
But the problem is i wanted to know if there is a better random function than the one i have.
Because right now i put
Min = 1
Max= 2
and it keeps picking 1
if i had min =1 and max =2 i want it to pick 1 sometimes and 2 sometimes
and now i tried min = 1 max = 3
and it never picks 3, it only picks 1 and 2
Code:
ok Code:
Public Class Form1 Public Function RandomNumber(ByVal MinNumber As Integer, ByVal MaxNumber As Integer) As Integer Dim r As New Random(System.DateTime.Now.Millisecond) Return Convert.ToInt32(r.Next(MinNumber, MaxNumber)) End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox(RandomNumber(1, 3)) End Sub End Class




Reply With Quote