首页 > 解决方案 > 如何随机生成4位数字?

问题描述

我正在使用这段代码:

byte[] intBytes = new byte[4];

rnd.GetBytes(intBytes);

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

上面的代码只生成3数字。我想让它生成4数字?

我已更改byte[4]byte[5]但仍只生成3数字?

标签: c#

解决方案


关于什么?

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

推荐阅读