How to generate 6 dig random number (within specific interval)? would
Random rand = new Random();
still work in this case? (e.g rand.Next(000000, 000101)) I need to keep 6dig format
asp.net C#
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to separate the numeric value from the text representation. 000101 is the same number as 101. Pick the random number using
Next(min, max)and then format it however you want, e.g. withvalue.ToString("000000")orvalue.ToString("D6")(whichever you find more readable).Note that you should take care when using
Random– there are a few subtle issues. (In particular, you very rarely want to actually create a new instance with the parameterless constructor in the line of code before you use it…)