You are here:

C#/Random numbers in C#.NET

Advertisement


Question
 Hy,

   How can I generate random numbers (int) in C#.NET?


 Thank you!

Answer
hi

here is my simple method generate random password for you can remove alphabet from this

int num = random.Next(1000); does this

here is another one more detail

public static string GetRandomPassword(int numChars, int seed)
     {
        string[] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "Q", "R", "S",
                        "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "8", "9" };
        
        Random rnd = new Random(seed);
        string random = string.Empty;
        for (int i = 0; i < numChars; i++)
        {
           random += chars[rnd.Next(0, 33)];
        }
        return random;
     }

Happy Programming!!

-srini

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder

©2012 About.com, a part of The New York Times Company. All rights reserved.