Unique 4 digit random number in C#

前端 未结 11 1910
失恋的感觉
失恋的感觉 2021-01-01 13:19

I want to generate an unique 4 digit random number. This is the below code what I have tried:

Code for generating random number

//Ge         


        
11条回答
  •  被撕碎了的回忆
    2021-01-01 14:03

    241 is a four digit number, if you use leading zeros: 0241.

    Display the returned number with a format string like this:

    String.Format("{0:0000}", n);

提交回复
热议问题