Generate random 6 digit number

前端 未结 6 2300
南方客
南方客 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:40

    I agree with the comment above that 000 001 can't be an integer, but can be a string with:

    Random generator = new Random();
    int r = generator.Next(1, 1000000);
    string s = r.ToString().PadLeft(6, '0');
    

提交回复
热议问题