如何随机生成4位数字?

时间:2019-07-02 11:32:03

标签: c#

我正在使用这段代码:

byte[] intBytes = new byte[4];

rnd.GetBytes(intBytes);

return Math.Abs(BitConverter.ToInt32(intBytes, 0)) % maxValue + 1;

上面的代码仅生成3位数字。我希望它生成4位数字吗?

我已将byte[4]更改为byte[5],但仍然只生成3个数字?

1 个答案:

答案 0 :(得分:-2)

那怎么办?

Random random = new Random();
int randomNumber = random.Next(1000, 10000);