Generate random 6 digit number

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

    You want to have a string:

    Random r = new Random();
    var x = r.Next(0, 1000000);
    string s = x.ToString("000000");
    

    For example,

    x = "2124"
    s = "002124"
    

提交回复
热议问题