06-04-2024, 11:37 PM
(06-04-2024, 01:17 AM)bplus Wrote:Drawing Numbers without Repetition
Code: (Select All)_Title "Drawing numbers without repetitions" 'b+ 2024-06-03
DefLng A-Z ' all variables are long
Randomize Timer
highest = 50 ' draw numbers from 1 to 50
drawNumber = 10 ' how many numbers to draw
restart:
ReDim deckOfNumbers(1 To highest) ' long also
' load the deck with numbers
For i = 1 To highest
deckOfNumbers(i) = i ' so the deck so far is very orderly
Next
' here is Fisher - Yates shuffle routine the most efficient known to mathematicians
For i = highest To 2 Step -1
Swap deckOfNumbers(i), deckOfNumbers(Int(Rnd * i) + 1) ' swap i with 1 to i
Next
' now the deck is shuffled !!! check it out
For i = 1 To drawNumber
Print deckOfNumbers(i);
Next
' now maybe we want to list numbers in order
ReDim order(1 To highest)
For i = 1 To drawNumber
order(deckOfNumbers(i)) = 1 ' mark the numbers in order
Next
For i = 1 To highest
If order(i) Then Print i;
Next
Print "... that should show:"; drawNumber; "numbers between 1 and"; highest; ", in order, no repeats."
Print: Print
Input " Please enter Highest number "; highest
Input " Please enter Draw number "; drawNumber
If highest <> 0 And drawNumber < highest Then GoTo restart
I got a shock when I saw this post!
Just last night I was working on this exact problem: are you spying on me ???
Here's what I ahd done: is this randomising less efficient than the one you used?
Code: (Select All)
For t = 1 To NumTickets
For a = 1 To 7 ' b is ball pick number
GetOne:
ball = Int(Rnd * 35) + 1 ' Ball is ball number
For b = 1 To 7
If Tickets(t, b) = ball Then
GoTo GetOne
End If
Next
Tickets(t, a) = ball
Next
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/