跳到主要內容

如何在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 for Applications 窗口。

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之間的隨機數,帶有2個小數位

插入隨機的整數/日期/時間,Kutools for Excel不會重複

Excel的Kutools's 插入隨機數據 可以在兩個數字之間插入隨機整數,而無需重複輸入Excel中的選定範圍。 請執行以下操作:

Excel的Kutools - 包含 300 多個 Excel 基本工具。 享受全功能 30 天免費試用,無需信用卡! 現在下載!

1。 選擇要插入隨機整數的範圍,然後單擊 庫工具 > 插入 > 插入隨機數據,請參見屏幕截圖:

2。 在 插入隨機數據 對話框, (1) 點擊 整型 標籤, (2) 在“從”和“到”框中,鍵入數字範圍,您將在之間生成隨機整數, (3) 檢查 獨特價值 選項, (4) 並點擊 Ok 按鈕。 看截圖:

這太棒了 插入隨機數據 該功能還支持插入無重複的隨機日期,無重複的隨機時間,隨機字符以及某些自定義列表中的無重複的隨機數據。

插入隨機日期(不包括週末),無需Kutools for Excel重複

通過Kutools for Excel插入隨機時間數據而無需重複

通過Kutools for Excel插入具有指定字符串長度的隨機字符

從某些自定義列表中插入隨機數據而無需Kutools for Excel的重複


演示:在兩個數字之間插入隨機(整數)數字,而無需在Excel中重複

Excel的Kutools:超過 300 個方便的工具觸手可及! 立即開始 30 天免費試用,沒有任何功能限制。 現在就下載!

相關文章:

生成範圍內的隨機字符串

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為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