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:11:23
 
 
À
11/11/2008 01:38:08
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:
01361021
Vues:
17
>>>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.
>
>Just a SWAG, but have you tried
>
>Dim loRnd As New Random()
>
Hi,
That was the original problem - instantiating Random objects with no parameter in a short time span results in them having the same seed - even using Ticks, as above, doesn't give a fine enough resolution.

Seems like the best solution is to keep a single Random instance.
Best,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform