none
random number generating function in c# RRS feed

Answers

  • Depends on what you mean by that. A true random generator cannot be obtained with a computer, unless you can have some truly random event to seed the generator. If all your application calls for is a pseudo random number generator (which is good for most practical purposes), you can use the Random class, or even go the extra mile and use the RNGCryptoServiceProvider.

    For a true random generator, you may want to look at http://random.org.

    HTH
    --mc

    Sunday, April 1, 2012 9:14 PM
  • Hi NabX,

    //The following code returns a random number:
    int num = random.Next();
    //The following code returns a random number less than 1000.
    int num = random.Next(1000);
    //The following code returns a random number between min & max:
    private int RandomNumber(int min, int max)
    {
    Random random = new Random();
    return random.Next(min, max); 
    }


    Regards, http://shwetamannjain.blogspot.com

    Monday, April 2, 2012 3:34 AM

All replies

  • The Random class.
    • Proposed as answer by Wyck Monday, April 2, 2012 12:08 AM
    Sunday, April 1, 2012 9:08 PM
  • Depends on what you mean by that. A true random generator cannot be obtained with a computer, unless you can have some truly random event to seed the generator. If all your application calls for is a pseudo random number generator (which is good for most practical purposes), you can use the Random class, or even go the extra mile and use the RNGCryptoServiceProvider.

    For a true random generator, you may want to look at http://random.org.

    HTH
    --mc

    Sunday, April 1, 2012 9:14 PM
  • Hi NabX,

    //The following code returns a random number:
    int num = random.Next();
    //The following code returns a random number less than 1000.
    int num = random.Next(1000);
    //The following code returns a random number between min & max:
    private int RandomNumber(int min, int max)
    {
    Random random = new Random();
    return random.Next(min, max); 
    }


    Regards, http://shwetamannjain.blogspot.com

    Monday, April 2, 2012 3:34 AM