Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generate same password in the same second
Message
De
11/11/2008 03:06:44
 
 
À
10/11/2008 23:54:54
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01360833
Message ID:
01361020
Vues:
15
This message has been marked as the solution to the initial question of the thread.
>>Try
Dim loRnd As New Random(CInt(DateTime.Now().Ticks And &HFFFFFFFF&))
>>( Casting in C# allows unchecked conversion ; VB doesn't)
>
>I replaced the line with this. It doesn't give an error. But, if I call this method twice, I end up with the same value. This is when I call it in the same second.

Hi,

Looks like even the Tick value doesn't change often enough in a tight loop. Probably best, as Gregory suggested, to use the same Random object. This obviously works:
   Sub Main()

        Static r As Random = New Random()

        Dim theNext As Integer
        Dim oldValue As Integer = r.Next()
        Do While True
            theNext = r.Next()
            Console.WriteLine(theNext.ToString())
            If theNext = oldValue Then GoTo 100
            oldValue = theNext
        Loop
100:
    End Sub
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform