ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   generating non-repeating random numbers in a range (https://www.excelbanter.com/excel-programming/378899-generating-non-repeating-random-numbers-range.html)

czuckett

generating non-repeating random numbers in a range
 
I'm trying to generate numbers for bingo cards - each row as 1 card - columns
A-E for the "B" numbers, columns F-J for the "I" numbers and so forth. How
do I get the numbers for each Bingo letter -"B", "I" not to repeat?

Tom Ogilvy

generating non-repeating random numbers in a range
 
generate the numbers you need, then "shuffle" them, then pick as many as you
need. Here is a shuffle routine you can incorporate.

Sub Shuffle()
'
' Algorithm from:
' The Art of Computer Programming: _
' SemiNumerical Algorithms Vol 2, 2nd Ed.
' Donald Knuth
' p. 139 [Algorithm P]
'
'
Dim list As Variant
Dim rng As Range
Dim t As Long, j As Long, k As Long
t = 100
Set rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
list = rng.Value
t = UBound(list, 1)
j = t
Randomize
For i = 1 To t
k = Rnd() * j + 1
lngTemp = list(j, 1)
list(j, 1) = list(k, 1)
list(k, 1) = lngTemp
j = j - 1
Next
rng.Value = list
End Sub


--

Regards,

Tom Ogilvy





"czuckett" wrote in message
...
I'm trying to generate numbers for bingo cards - each row as 1 card -
columns
A-E for the "B" numbers, columns F-J for the "I" numbers and so forth.
How
do I get the numbers for each Bingo letter -"B", "I" not to repeat?





All times are GMT +1. The time now is 03:11 PM.

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