Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
b+ Beginners Corner
#57
(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
Print

' 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
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 ???  Big Grin
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.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Messages In This Thread
b+ Beginners Corner - by bplus - 05-20-2023, 06:34 PM
RE: b+ Beginners Corner - by vince - 05-20-2023, 06:47 PM
RE: b+ Beginners Corner - by bplus - 05-20-2023, 07:11 PM
RE: b+ Beginners Corner - by PhilOfPerth - 05-26-2023, 12:12 AM
RE: b+ Beginners Corner - by bplus - 05-26-2023, 04:11 PM
RE: b+ Beginners Corner - by PhilOfPerth - 05-26-2023, 11:18 PM
RE: b+ Beginners Corner - by mnrvovrfc - 05-27-2023, 12:15 AM
RE: b+ Beginners Corner - by PhilOfPerth - 05-27-2023, 02:27 AM
RE: b+ Beginners Corner - by bplus - 05-29-2023, 12:07 AM
RE: b+ Beginners Corner - by bplus - 05-29-2023, 01:37 AM
RE: b+ Beginners Corner - by mnrvovrfc - 05-29-2023, 02:29 AM
RE: b+ Beginners Corner - by bplus - 05-30-2023, 04:17 PM
RE: b+ Beginners Corner - by bplus - 06-15-2023, 03:06 PM
RE: b+ Beginners Corner - by GareBear - 06-15-2023, 07:50 PM
RE: b+ Beginners Corner - by bplus - 06-15-2023, 10:42 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 02:46 PM
RE: b+ Beginners Corner - by CharlieJV - 06-23-2023, 03:26 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 08:28 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-23-2023, 09:45 PM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 09:56 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-24-2023, 02:47 AM
RE: b+ Beginners Corner - by bplus - 06-23-2023, 10:02 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 02:35 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 02:52 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 07:48 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-24-2023, 08:02 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 08:40 PM
RE: b+ Beginners Corner - by TerryRitchie - 06-24-2023, 10:07 PM
RE: b+ Beginners Corner - by bplus - 06-24-2023, 09:08 PM
RE: b+ Beginners Corner - by Dimster - 06-24-2023, 09:12 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-24-2023, 11:44 PM
RE: b+ Beginners Corner - by bplus - 06-25-2023, 02:27 PM
RE: b+ Beginners Corner - by OldMoses - 06-25-2023, 05:49 PM
RE: b+ Beginners Corner - by bplus - 06-25-2023, 06:40 PM
RE: b+ Beginners Corner - by OldMoses - 06-25-2023, 08:03 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 01:14 AM
RE: b+ Beginners Corner - by mnrvovrfc - 06-26-2023, 02:26 AM
RE: b+ Beginners Corner - by Ultraman - 06-26-2023, 11:29 AM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 12:17 PM
RE: b+ Beginners Corner - by Ultraman - 06-26-2023, 12:21 PM
RE: b+ Beginners Corner - by Dimster - 06-26-2023, 02:38 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 03:32 PM
RE: b+ Beginners Corner - by bplus - 06-26-2023, 04:48 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 01:29 AM
RE: b+ Beginners Corner - by OldMoses - 06-27-2023, 11:49 AM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 12:40 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-27-2023, 02:12 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 03:22 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-27-2023, 05:21 PM
RE: b+ Beginners Corner - by bplus - 06-27-2023, 05:48 PM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 03:20 AM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 02:54 PM
RE: b+ Beginners Corner - by mnrvovrfc - 06-28-2023, 07:07 PM
RE: b+ Beginners Corner - by Dimster - 06-28-2023, 09:50 PM
RE: b+ Beginners Corner - by bplus - 06-28-2023, 10:27 PM
RE: b+ Beginners Corner - by bplus - 06-04-2024, 01:17 AM
RE: b+ Beginners Corner - by PhilOfPerth - 06-04-2024, 11:37 PM
RE: b+ Beginners Corner - by bplus - 06-05-2024, 12:42 AM
RE: b+ Beginners Corner - by gaslouk - 06-05-2024, 02:37 PM
RE: b+ Beginners Corner - by bplus - 06-30-2024, 07:38 PM
RE: b+ Beginners Corner - by bplus - 07-01-2024, 03:42 PM
RE: b+ Beginners Corner - by aurel - 07-01-2024, 06:16 PM
RE: b+ Beginners Corner - by bplus - 07-01-2024, 07:39 PM
RE: b+ Beginners Corner - by bplus - 07-07-2024, 06:42 PM



Users browsing this thread: 4 Guest(s)