Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Password generation using C#.NET

Status
Not open for further replies.

z07924

IS-IT--Management
Feb 18, 2002
122
0
0
GB
// Random Password Generation

VB.NET
Randomize()
whatsNext = Int((1 - 0 + 1) * Rnd() + 0)
strNewPass = strNewPass & Chr(Int((upper - lower + 1) * Rnd() + lower))

The above two lines are in visual basic.net. I have converted the above lines to C#.NET. It is given below.

C#.NET
Random RandomGenerator = new Random(20);
whatsNext = (int)((1 - 0 + 1) * RandomGenerator.Next() + 0);
strNewPass = strNewPass + (char)((int)((upper - lower + 1) * RandomGenerator.Next() + lower));

I have tried the same code executing in VB.NET, it is working fine. somehow I couldn't get the same result when I have tried in C#.NET.

Is there anything wrong?
If anyone know the solution, let me know.

Thanks in Advance.
 
The Rnd and Random methods are language-specific, so I'm not surprised they act differently.

If you want something truly random, investigate the System.Security.Cryptography namespace. It has a class named RNGCryptoServiceProvider, which has a method named GetBytes.

Since this method is part of the framework, not part of the language, it will work the same no matter which .NET language you use.

Chip H.



If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top