Android Question Random numbers - Dominoes getting a lot of sixes

Arf

Well-Known Member
Licensed User
Longtime User
I've tried using Rnd(0,7) as well Erel's SecureRandom generation function, but with both I seem to get 6's come up very often, and many in a row also. In fact the numbers seem to roll high, here's six Rnd(0, 7) outputs in each row:

6,6,6,6,5,5 - average 34
6,6,1,6,0,3 - average 22
1,4,5,5,5,6 - average 26
3,4,5,6,5,6 - average 29
2,4,3,6,2,3 - average 20

Anyone seen this before?
 

Arf

Well-Known Member
Licensed User
Longtime User
Oh hang on, ignore. The numbers I put are not successive Rnd(0, 7) outputs, they're domino tile outputs and the average is going to be high because of the algorithm, silly me.

firstdomNum = Rnd(0, 7)
secondDomNum = Rnd(firstDomNum, 7)

I didn't think the algorithm through very well!
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
Not that it was your problem, but on a side note, I *fake* more "randomness" in one app by using something along the lines of:
B4X:
X1 = RND(0, 10)
x2 = RND(1, 9)
If X2 >= X1 Then X2 = X2 + 1

That way I never get the same number twice in a row. Mathematically not right, but gives the impression of more "randomness" to the user.
 
  • Like
Reactions: Arf
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Depending on how quickly you generate random numbers, you might end up with pairs (or more) of the same number due to the fact that the Rnd function uses the system clock to seed - so if you generate 2 or more numbers in the same clock tick, you'll likely end up with the same number. I found in my yahtzee game that this was a common problem with the loop that does the dice rolls, so I ended up creating an array of 8 random numbers, then using Rnd to select one of the elements in the array.

- Colin.
 
Upvote 0
Top