Generate random 6 digit number

前端 未结 6 2301
南方客
南方客 2020-12-29 20:25

I\'ve been searching for a couple of hours and I just can\'t seem to find a answer to this question. I want to generate a random number with 6 digits. Some of you might tell

6条回答
  •  感情败类
    2020-12-29 20:35

    As stated in a comment, a "six digit number" is a string. Here's how you generate a number from 0-999999, then format it like "000482":

    Random r = new Random();
    int randNum = r.Next(1000000);
    string sixDigitNumber = randNum.ToString("D6");
    

提交回复
热议问题