Jellby wrote: ↑20 February 2025, 09:40
It seems you're more concerned about efficiency than fairness.
I'm not concerned about fairness at all. At least not yet.
In the last 10 games I've played, combined number of 1,1 rolls and 6,6 rolls have been higher than the 1-out-of-18 one would expect. And the number of 8s has been more than the number of 6s. If this kept up for another 100 games, I might begin to be concerned.
I once lost at blackjack for 22 consecutive hands at a real table. (Or rather, didn't win in 22 consecutive hands. There were some pushes in there.) This is easy to do on purpose but not easy to do when playing near-perfect strategy. Weird things happen in life. It would have been more fun to win 22 consecutive hands.
I was simply curious what algorithm BGA decided on for their millions of die rolls.
Jellby wrote: ↑20 February 2025, 09:40
Even if underlying code does the naive (and maybe "wrong") thing:
The naive algorithm I described is not wrong. It results in a fair die roll.
It simply uses more bits than it needs to. (Or possibly my naive algorithm is optimal, but I wouldn't think so.) And, as I tried to say before, who cares if some psuedo-random bits get "wasted"? Psuedo-random bits are very cheap.
Jellby wrote: ↑20 February 2025, 09:40
generate a random uniformly-distributed real number in the range [0,1), get an integer as floor(6*x)+1 (that could be wrong because 2^n is not divisible by 6, so some intervals would be ever so slightly more likely than others). Even if that's the case, the practical effect would be completely negligible.
I remember, back in the 80s, that 1+floor(6x), where x ∈ [0,1), was common. Because IIRC that's the only randomness the Basic language provided.
However I doubt that Basic's RND was precisely uniform. I think to generate a truly uniformly distributed floating point value would be tricky, but I've never tried it. In common floating point formats, there are more bit combinations denoting values in [0.0,0.5) than there are for [0.5,1.0).
I think it's better to stay in the integer realm.
If you do 1+(n%6), where n is a 32-bit unsigned integer. Then (unless I messed up the math) you get:
1: 715,827,883 bit combinations
2: 715,827,883 bit combinations
3: 715,827,883 bit combinations
4: 715,827,883 bit combinations
5: 715,827,882 bit combinations
6: 715,827,882 bit combinations
Rolling a 1 (or 2, or 3, or 4) would be 1.0000000014 times more likely to occur than a 5 (or 6), not a fair roll.
Is this "completely negligible"? Maybe, but I'd be disappointed if BGA did their rolls this way, or even if they did the same thing with a 64-bit integer.
The naive algorithm is better. And the naive algorithm usually (but not always) uses way fewer than 32 bits.