How do you generate a random number in C#?

前端 未结 6 1766
天命终不由人
天命终不由人 2020-12-25 12:34

I would like to generate a random floating point number between 2 values. What is the best way to do this in C#?

6条回答
  •  执念已碎
    2020-12-25 13:06

    How random? If you can deal with pseudo-random then simply:

    Random randNum = new Random();
    randNum. NextDouble(Min, Max);
    

    If you want a "better" random number, then you probably should look at the Mersenne Twister algorithm. Plenty of people hav already implemented it for you though

提交回复
热议问题