How do I generate a random int number?

前端 未结 30 2620
长发绾君心
长发绾君心 2020-11-21 11:02

How do I generate a random integer in C#?

30条回答
  •  逝去的感伤
    2020-11-21 11:43

    I used below code to have a random number (not recommended):

    var random = new Random((int)DateTime.Now.Ticks);
    var randomValue = random.Next(startValue, endValue + 1);
    

提交回复
热议问题