I have a problem. I'm trying to generate a random number 'x' amount of times. I get a random number but I'm getting the same number repeated over and over. I need a random number each time. What am I doing wrong?
VB.NET:
Private Function RandomNumber(ByVal min As Integer, ByVal max As Integer) As Integer
Dim random As New Random()
Return random.Next(min, max)
End Function 'RandomNumber
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objTextStream
Dim strFileName = System.AppDomain.CurrentDomain.BaseDirectory() & "chartdata.xml"
'set constant for writing
Const fsoForWriting = 2
objTextStream = objFSO.OpenTextFile(strFileName, fsoForWriting)
Dim x
Dim myvalue As Integer = 0
objTextStream.WriteLine("<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbCrLf)
objTextStream.WriteLine("<chart>" & vbCrLf)
Dim ran As New Random
Random.Next(0, 100)
For x = 1 To Int(TextBox5.Text)
myvalue = 0
myvalue = RandomNumber(0, 1000)
objTextStream.WriteLine("<chartdata>")
objTextStream.WriteLine("<YEAR>" & x & "</YEAR>")
objTextStream.writeline("<" & Replace(TextBox1.Text, " ", "_") & ">" & myvalue & "</" & Replace(TextBox1.Text, " ", "_") & ">")
objTextStream.WriteLine("</chartdata>" & vbCrLf)
Next
objTextStream.WriteLine("</chart>" & vbCrLf)
'Close the file and clean up
objTextStream.Close()
objTextStream = Nothing
objFSO = Nothing
Response.Redirect("~/default5.aspx")
End Sub
End Class