Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generate same password in the same second
Message
De
10/11/2008 02:17:38
 
 
À
10/11/2008 02:16:13
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:
01360838
Vues:
44
>>The remarks in the doc
>>
>>However, because the clock has finite resolution, using the parameterless constructor to create different Random objects in close succession 
>>creates random number generators that produce identical sequences of random numbers.
>>
>>
>>I see two possibilities
>>(1) Use a constructor with a parameter - the syntax will be C# as I'm not familiar with vb
>>
>>var loRnd = new Random((int)DateTime.Now.Ticks);
>>
>>
>>(2) If that does not help - make loRnd a static field so that the next sequence will always be different
>>
>>
>>I'm in favour of (2)
>
>Method number one, as converted as this:
>
>
>Dim loRnd = New Random(CInt(DateTime.Now.Ticks)) 
>
>
>gives an arithmetic operation resulted in an overflow.

try
dim loRnd = new Random( DateTime.Now.Ticks.GetHashCode() );
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform