Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
getting numbers divisible by 4 from random numbers in ascending order | Excel Worksheet Functions | |||
I want random numbers generated without repeating numbers | Excel Worksheet Functions | |||
Can Excel pick random numbers from 1-300 and not repeat numbers? | Excel Discussion (Misc queries) | |||
Non-random numbers generated by excel's data analysis random gener | Excel Worksheet Functions | |||
Non-random numbers generated by excel's data analysis random gener | Excel Discussion (Misc queries) |