ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Different Random Numbers (https://www.excelbanter.com/excel-programming/302152-re-different-random-numbers.html)

Jim Cone

Different Random Numbers
 
Jake,

The following code is a modification of the code in my "Bingo" workbook.
'-------------------------------------------------------------------------------------------------------

Sub Shuffle30Values()
'Jim Cone - June 22, 2004
'Lists five random numbers between 1 and 15 in a column (no dupes)
'Lists five random numbers between 16 and 30 in the adjoining column (no dupes)

Dim lngTemp As Long
Dim lngNum As Long
Dim lngRow As Long
Dim lngCol As Long
Dim Arr() As Long
Dim i As Long
Dim j As Long

'For numbers from 1 to 30
lngNum = 30
'First row in which the numbers will be displayed
lngRow = 5

'Columns D and Columns C
For lngCol = 4 To 3 Step -1
ReDim Arr((lngNum - 14) To lngNum, 1 To 1)
'Add values to the array
For i = (lngNum - 14) To lngNum
Arr(i, 1) = i
Next 'i
'Move each array value to a new random position.
For i = lngNum To (lngNum - 14) Step -1
Randomize (Right(Timer, 2) * i)
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
j = Int(15 * Rnd + (lngNum - 14))
lngTemp = Arr(i, 1)
Arr(i, 1) = Arr(j, 1)
Arr(j, 1) = lngTemp
Next 'i

'Add first five numbers from the array to the worksheet.
Range(Cells(lngRow, lngCol), Cells(lngRow + 4, lngCol)).Value = Arr()
lngNum = lngNum - 15
Next 'lngCol

End Sub
'------------------------------------------------------------------------------------------------------------

The workbook creates 2 completely different formatted bingo cards on a worksheet and then
prints the quantity requested. Each bingo card is unique.
The workbook is available for free upon direct request.
Remove xxx from my email address.

Regards,
Jim Cone
San Francisco, CA
XX

"Jake" wrote in message ...
I would like to make a list of five random numbers between 1 and 15, and then another set of five between 16 and 30. I want to be

able to regenerate the numbers quickly, like the rand or randbetween function is capable of doing, but it is necessary that each of
these random numbers is always different from the other ones (ie: no duplicates) after being generated. (eg. 3,6,12,5,8 is good,
2,4,14,14,2 is not). I'm sure that's more than clear, but I just wanted to make sure.



All times are GMT +1. The time now is 06:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com