jeudi 21 janvier 2016

Why isn't the random number sequence the same?

I wrote this code below, expecting it to return the same thing each time I ran it, and it did not. May someone explain to me why A specifically seeded Random Number Generator would generate a different number each time I run it, because i wrote the same program as a command line application and it worked just fine.

Here is my VB.NET code (broken code):

'Bunch of WinForms Code
Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.Click
   Randomize(3)
   MsgBox(Rnd.ToString)
End Sub

Here is my working VB.NET Command Line Application:

Imports System.Console
Public Module rnum
    Sub Main()
        Randomize(3)
        WriteLine(Rnd.ToString) 'Returns 0.1387751
    End Sub
End Module




Aucun commentaire:

Enregistrer un commentaire