c# - 如何随机生成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
数字?
解决方案
关于什么?
Random random = new Random();
int randomNumber = random.Next(1000, 10000);
推荐阅读
- c# - 绑定不适用于应用程序资源
- python - 熊猫数据框中的跨列搜索
- r - 如何找到事件/字母/的发生模式?
- php - 无法在 PHP 中获取查询字符串(初学者/简单问题?)
- gradle - 如何编写一个 gradle 构建任务,该任务在与我的 gradle 构建文件不同的目录中运行诸如“npm install”之类的脚本?
- javascript - 在 PHP 中返回没有值
- python - 使用 BeautifulSoup 解析内容
- java - 如何创建一个新文件并放置一些用户定义的整数(使用 Scanner 类)然后读取它?
- pandas - Pandas DataFrame 清理
- c - 为 C/C++ 安装 openSSL MacOs X gcc-9 时遇到问题