FireBFM Posted April 4, 2012 Share Posted April 4, 2012 (edited) What i have. For x = 1 to 9 Num = Int(Rnd*3) + 1 Next X theres 9 command boxes control array. each one will be assigned a random # 1 to 3. But i can only use 3 ones, 5 twos and 1 three. Help with bolded part Edited April 4, 2012 by FireBFM Link to comment Share on other sites More sharing options...
md65536 Posted April 5, 2012 Share Posted April 5, 2012 What i have. For x = 1 to 9 Num = Int(Rnd*3) + 1 Next X theres 9 command boxes control array. each one will be assigned a random # 1 to 3. But i can only use 3 ones, 5 twos and 1 three. Help with bolded part You could keep track of how many of each digit you have left and "reroll" if Num is a digit you've used up. I assume though that this isn't what you want, because the last boxes will tend to be a 2 more likely than the first boxes. I'd probably just put the numbers (1,1,1,2,2,2,2,2,3) in an array and randomly select an index, and remove that choice from the array. Link to comment Share on other sites More sharing options...
FireBFM Posted April 9, 2012 Author Share Posted April 9, 2012 I'd probably just put the numbers (1,1,1,2,2,2,2,2,3) in an array and randomly select an index, and remove that choice from the array. Code please? Link to comment Share on other sites More sharing options...
timo Posted April 9, 2012 Share Posted April 9, 2012 (edited) The translation to Visual Basic and the extension to "9 command boxes control array" (whatever that is) should be straightforward. Edited April 9, 2012 by timo Link to comment Share on other sites More sharing options...
md65536 Posted April 9, 2012 Share Posted April 9, 2012 (edited) Code please? I don't know VB so consider this pseudocode... dim Digits(0 to 8) as Integer Digits(0) = 1 Digits(1) = 1 Digits(2) = 1 Digits(3) = 2 Digits(4) = 2 Digits(5) = 2 Digits(6) = 2 Digits(7) = 2 Digits(8) = 3 for x = 8 to 0 step -1 ' select a random index from 0 to x Index = Int(Rnd * (x+1)) Num = Digits( Index ) ' Remove that digit from the array (effectively we're shrinking the array, and overwriting the used digit) Digits( Index ) = Digits( x ) next x It might require some debugging. Edited April 9, 2012 by md65536 Link to comment Share on other sites More sharing options...
FireBFM Posted April 9, 2012 Author Share Posted April 9, 2012 For X = 1 To 9 Num = (X - 1) \ 4 + 1 N = Int(Rnd * 9) + 1 cmdTile(N).Caption = Num Next X N has duplicates. So some of the tiles are blank. Help! Link to comment Share on other sites More sharing options...
Xittenn Posted April 9, 2012 Share Posted April 9, 2012 Use a list and remove each item as it is used! So populate a list with 3-1's, 5-2's, and a 3, and then randomly pick from the list removing the picked item each time. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now