Jump to content

Recommended Posts

Posted (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 by FireBFM
Posted

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.

Posted

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?

Posted (edited)

random_number.png

The translation to Visual Basic and the extension to "9 command boxes control array" (whatever that is) should be straightforward.

Edited by timo
Posted (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 by md65536
Posted

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!

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.