Answered by:
random number generating function in c#
Question

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 Proposed as answer by Lie YouModerator Tuesday, April 3, 2012 6:15 AM
 Marked as answer by Lie YouModerator Friday, April 6, 2012 1:32 AM

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
 Proposed as answer by Shweta Jain (Lodha) Monday, April 2, 2012 3:34 AM
 Marked as answer by Lie YouModerator Friday, April 6, 2012 1:32 AM
All replies


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 Proposed as answer by Lie YouModerator Tuesday, April 3, 2012 6:15 AM
 Marked as answer by Lie YouModerator Friday, April 6, 2012 1:32 AM

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
 Proposed as answer by Shweta Jain (Lodha) Monday, April 2, 2012 3:34 AM
 Marked as answer by Lie YouModerator Friday, April 6, 2012 1:32 AM