跳到主要内容

如何在Excel中不重复的情况下在两个数字之间插入随机(整数)数字?

您是否需要在Microsoft Excel中插入随机数? 有几种方法可以在范围内插入随机数,如下所示:

通过公式插入随机数

通过VBA插入具有指定小数位的随机数

插入随机整数/日期/时间,无重复/重复

在两个数字/日期/时间之间随机插入整数/日期/时间,无需重复

Kutools for Excel的 插入随机数据 该实用程序使您可以轻松地在两个特定数字之间插入随机整数(整数),在两个日期之间随机插入一系列日期(仅工作日或仅周末,或无限制),两次之间随机插入一系列时间,或生成随机数具有一定长度的文本字符串。 和 独特价值 选项将阻止插入重复项。



使用RAND函数和RANDBETWEEN公式在两个数字之间插入随机数

此方法将应用RAND函数和RANDBETWEEN函数将两个数字之间的随机数插入Excel中的指定范围。 请查看以下公式:

公式 说明(结果)
= RAND() 0到1之间的随机数(可变)
=兰德()* 100 0到100之间的随机数(可变)
= RANDBETWEEN(低,高) 两个给定整数之间的随机整数,例如RANDBETWEEN(50,100)。

请参阅以下屏幕截图:

0到1之间的随机数
= RAND()
0到1之间的随机数
0到100之间的随机数
=兰德()* 100
0到100之间的随机数
50至100之间的随机整数
= RANDBETWEEN(50,100)
50至100之间的随机整数

通过VBA在具有指定小数位的两个数字之间插入随机数

下面的VBA可以帮助您将任意随机整数或具有给定小数位的随机数插入Excel中的指定范围。 请执行以下操作:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块窗口。

Public Function RandomNumbers(Num1 As Long, Num2 As Long, Optional Decimals As Integer)
'Update20131113
Application.Volatile
Randomize
If IsMissing(Decimals) Or Decimals = 0 Then
    RandomNumbers = Int((Num2 + 1 - Num1) * Rnd + Num1)
Else
    RandomNumbers = Round((Num2 - Num1) * Rnd + Num1, Decimals)
End If
End Function

3。 保存并关闭代码,然后在空白单元格中输入此公式 = RandomNumbers(X,Y,Z), X 表示数字的下限, Y 指示数字的上限,并且 Z 是指定的随机数小数位。

例如,我要生成50到1000之间的一些整数,可以插入此公式 =随机数(50,1000,0); 并使用此公式=在50到100之间插入2位小数的随机数随机数(50,100,2)。 请参阅以下屏幕截图:

插入不带小数位的随机数:
50至100之间的随机整数
插入带有2个小数位的随机数:
50到500之间的随机数,带有两位小数

通过 Kutools for Excel 插入随机整数/日期/时间而不重复

Kutools for Excel's 插入随机数据 可以在两个数字之间插入随机整数,而无需重复输入Excel中的选定范围。 请执行以下操作:

Kutools for Excel - 包含 300 多个 Excel 基本工具。 享受全功能 30 天免费试用,无需信用卡! 现在下载!

1。 选择要插入随机整数的范围,然后单击 库工具 > 插页 > 插入随机数据,请参见屏幕截图:

2。 在 插入随机数据 对话框, (1) 点击 整数 标签, (2) 在“从”和“到”框中,键入数字范围,您将在之间生成随机整数, (3) 检查 独特价值 选项, (4) 并单击 Ok 按钮。 看截图:

这太棒了 插入随机数据 该功能还支持插入无重复的随机日期,无重复的随机时间,随机字符以及某些自定义列表中的无重复的随机数据。

Kutools for Excel 插入随机日期(不包括周末)而不重复

通过 Kutools for Excel 插入不重复的随机时间数据

通过 Kutools for Excel 插入指定字符串长度的随机字符

Kutools for Excel 从某些自定义列表插入随机数据而不重复


演示:在两个数字之间插入随机(整数)数字,而无需在Excel中重复

Kutools for Excel:超过 300 个方便的工具触手可及! 立即开始 30 天免费试用,没有任何功能限制。 立即下载!

相关文章:

生成一定范围内的随机字符串

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!

Comments (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I need random incremental decimal values in a range. range 22.1234 to 79.1234 and from row 1 to row 300. how to do it........?
This comment was minimized by the moderator on the site
5. Try to accomplish the following with your prior knowledge of basic Excel programming. [6] 5.1 Let’s say you’re interested in studying student attitudes toward climate change. If you wanted to randomly sample 50 students out of 643 at a local school, you would need to begin by creating a numbered list of all 643 students (student =1; student =2, student =3 and so forth). Then all you would need to do is to generate a set of random numbers with a range from 1 to 643. Use Excel to accomplish this task. Arrange your list from smallest to largest number. 5.2 Although people sometimes confuse random assignment with random sampling, the two are really quite different. With random sampling, the goal is to choose a representative set of cases from the full population under consideration. With random assignment, the goal is usually to give all participants and equal chance of being assigned to each experimental condition (regardless of how representative the participants are).
This comment was minimized by the moderator on the site
i just want to win PCH 10,000.00 can you help
This comment was minimized by the moderator on the site
i would like to random my number 5035 4902 4950 4944 ID 4857-62 4650 tv276 5979 3818
This comment was minimized by the moderator on the site
good website I helped me a lot
This comment was minimized by the moderator on the site
Please review this Random Number Generator. Let's talk tomorrow. Thanks Rob
This comment was minimized by the moderator on the site
Wow, cool, just what I was looking for. Seems Excel 2010 is kind of lame when it comes to options for random numbers.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations