random - new seed every call

elic05

Member
Joined
Nov 2, 2008
Messages
19
Programming Experience
Beginner
I use

VB.NET:
Dim randObj As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod 2147483647))
Dim rndNum As Integer = randObj.Next(0, 1000)
inside a function that i call five times
in order to get 5 different numbers

it works fine when i run the website on localHost
but on the remote server most of the 5 numbers that i get are the same (eg: 17,52,52,52,52)

how can this problem be solved?
thanks
 
VB.NET:
    Private shared randObj As New Random(Convert.ToInt32(DateTime.Now.Ticks Mod 2147483647))

    Private Function getNextRandom() As Integer
        Return randObj.Next(0, 1000)
    End Function

You should have the randObj only created once, this way when you next try and get a random number from it, it will get a different one.

Hope this helps

Satal :D
 
Back
Top