Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,549 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,848 people online right now. Registration is fast and FREE... Join Now!




Non Repeating Random Numbers

 
Reply to this topicStart new topic

Non Repeating Random Numbers, Bingo Game

Gus
20 Aug, 2008 - 01:51 AM
Post #1

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 7

This is the code i used form this site. I would like to change it and make a bingo game showing all the numbers previously called.

In appreciation.
Gus

CODE
Private Sub Form_Load()

  'assure random numbers don't
  'repeat each run
   Randomize
      
End Sub
        
        
Private Sub Command1_Click()

  'Set the number of elements needed. This demo
  'uses 1 to 52 to simulate a deck of cards.
   Dim cnt As Long
   Dim myArray(1 To 52) As Long
  
  'lists are for info only
   List1.Clear
   List2.Clear
  
  'fill the array with consecutive numbers from 1 to 52
   For cnt = 1 To UBound(myArray)
      myArray(cnt) = cnt

     'debug/info only - not needed for routine
      List1.AddItem cnt & vbTab & myArray(cnt)
   Next
  
  'randomize (suffle) the array values
   RandomizeArray myArray
  
  'debug/info only - not needed for routine
   For cnt = 1 To UBound(myArray)
      List2.AddItem cnt & vbTab & myArray(cnt)
   Next
   'this is what i need
   Text1.Text = Val(myArray(1))
   End Sub


Private Sub RandomizeArray(ArrayIn As Variant)
  
   Dim cnt As Long
   Dim RandomIndex As Long
   Dim tmp As Variant
  
  'only if an array was passed
   If VarType(ArrayIn) >= vbArray Then
        
     'loop through the array elements in reverse
      For cnt = UBound(ArrayIn) To LBound(ArrayIn) Step -1
      
        'select a random array index
         RandomIndex = Int((cnt - LBound(ArrayIn) + 1) * _
                       Rnd + LBound(ArrayIn))
                                    
        'cnt represents one array member
        'index, and RandomIndex represents
        'another, so swap the data held in
        'myarray(cnt) with that in myarray(RandomIndex)
         tmp = ArrayIn(RandomIndex)
         ArrayIn(RandomIndex) = ArrayIn(cnt)
         ArrayIn(cnt) = tmp
        
      Next
      
   Else
  
     'The passed argument was not an
     'array; error handler goes here
      
   End If
  
End Sub


Private Sub List1_Scroll()

  'if List2 is scrolled, keep List1 in sync
   List2.TopIndex = List1.TopIndex
  
End Sub


Private Sub List2_Scroll()

  'if List1 is scrolled, keep List2 in sync
   List1.TopIndex = List2.TopIndex

End Sub



User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Non Repeating Random Numbers
20 Aug, 2008 - 02:51 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 39 times
Dream Kudos: 25
My Contributions
Is your question that you're not sure where to insert the code to display numbers, or not sure how to write the code to display numbers?
User is offlineProfile CardPM
+Quote Post

Gus
RE: Non Repeating Random Numbers
21 Aug, 2008 - 06:47 AM
Post #3

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 7

I do not have a clue how to write the code. i could work with what i've got and probably figure out through trial and error exactly where to place it. I would need to insert another text box thats about all i do know.
User is offlineProfile CardPM
+Quote Post

cmount
RE: Non Repeating Random Numbers
21 Aug, 2008 - 10:09 AM
Post #4

New D.I.C Head
*

Joined: 1 Aug, 2008
Posts: 41



Thanked: 1 times
My Contributions
QUOTE(Gus @ 21 Aug, 2008 - 07:47 AM) *

I do not have a clue how to write the code. i could work with what i've got and probably figure out through trial and error exactly where to place it. I would need to insert another text box thats about all i do know.


I'm no coding expert, so I'm sorry I can't be more help than just to throw out ideas that might not help at all--I'm just hoping they might give you an idea on how to maybe accomplish it or some directions you could take with this.

I don't entirely follow exactly what your demo code is doing. I'm having trouble seeing where it's going to assign the individual numbers suits (like spades, clubs, etc.)

But I do know you have an array, each array position should be assigned a card value (like King of Spades). Then it picks a random number in the array & displays the card associated w/ that number.

To adapt it to bingo (before even considering how to show numbers that have been called), you'll have to adapt each array position to allow for the possible bingo values B1-O(whatever)
#'s 1-15 (I think) are associated w/ B, and #'s 16-30 go with I...etc.
I'm not sure about the rules offhand...you can look that up. But you'll need to have it say if the random number chosen is, for example 1, it says ok the array number is less than or equal to 15 and greater than 0, so the letter is B.

Then it adds the array's number onto the letter B. You'd probably want to do this in a string.

Then if the number is greater than 16 & less than or equal to wherever "I" ends, it adds "I"+array# for that.

You'll probably want it to sort the randomly picked values according to their Bingo value, so say O74 is called, then B 2, then I 17, then B 5
It'll have a column with all the B's sorted in order: B2, B5
Then a column with I's, etc. Every time a new number is selected, it will need to append that to the appropriate column & re-sort the list.

Or you might do something in VBA for MS Excel where you have your excel spreadsheet columns laid out like the numbers. Then when a number is called, it makes the font of the cell that corresponds to that bingo value BOLD & underlines it (actually might even be better to use the highlight part of excel). Then you'd have a graphical display of what numbers have & haven't been called

This would probably be the best way to go.

It'll be a pain to code, but you should always start simpler & then build up to the bigger goals (like having it DISPLAY the stuff properly). First you have to have it be able to pick a random bingo value & store it in some list/array.


User is offlineProfile CardPM
+Quote Post

Gus
RE: Non Repeating Random Numbers
21 Aug, 2008 - 11:47 AM
Post #5

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 7

Sorry if i have misled anyone, in the UK we play bingo differently, we do not use B-I-N-G-O as headers just numbers 1To 90. I was using the card game as a learning curve for coding experience really. I have managed to get it working but the numbers sometimes repeat which is not good, i can tweak a bit more and with the forums help get the whole thing going. I still need to know how to store all the previous numbers called. In aText Box if possible. Im using Access 2002 which is a bit different but im managing ok.
Cheers Gus.
QUOTE(cmount @ 21 Aug, 2008 - 11:09 AM) *

QUOTE(Gus @ 21 Aug, 2008 - 07:47 AM) *

I do not have a clue how to write the code. i could work with what i've got and probably figure out through trial and error exactly where to place it. I would need to insert another text box thats about all i do know.


I'm no coding expert, so I'm sorry I can't be more help than just to throw out ideas that might not help at all--I'm just hoping they might give you an idea on how to maybe accomplish it or some directions you could take with this.

I don't entirely follow exactly what your demo code is doing. I'm having trouble seeing where it's going to assign the individual numbers suits (like spades, clubs, etc.)

But I do know you have an array, each array position should be assigned a card value (like King of Spades). Then it picks a random number in the array & displays the card associated w/ that number.

To adapt it to bingo (before even considering how to show numbers that have been called), you'll have to adapt each array position to allow for the possible bingo values B1-O(whatever)
#'s 1-15 (I think) are associated w/ B, and #'s 16-30 go with I...etc.
I'm not sure about the rules offhand...you can look that up. But you'll need to have it say if the random number chosen is, for example 1, it says ok the array number is less than or equal to 15 and greater than 0, so the letter is B.

Then it adds the array's number onto the letter B. You'd probably want to do this in a string.

Then if the number is greater than 16 & less than or equal to wherever "I" ends, it adds "I"+array# for that.

You'll probably want it to sort the randomly picked values according to their Bingo value, so say O74 is called, then B 2, then I 17, then B 5
It'll have a column with all the B's sorted in order: B2, B5
Then a column with I's, etc. Every time a new number is selected, it will need to append that to the appropriate column & re-sort the list.

Or you might do something in VBA for MS Excel where you have your excel spreadsheet columns laid out like the numbers. Then when a number is called, it makes the font of the cell that corresponds to that bingo value BOLD & underlines it (actually might even be better to use the highlight part of excel). Then you'd have a graphical display of what numbers have & haven't been called

This would probably be the best way to go.

It'll be a pain to code, but you should always start simpler & then build up to the bigger goals (like having it DISPLAY the stuff properly). First you have to have it be able to pick a random bingo value & store it in some list/array.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:02PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month