Closed brubraz closed 2 months ago
Is it possible to manually seed the new function? The reason this all was done is because people were complaining about other people abusing undo to achieve a more desired random result (for example undo and redo a mulligan, or a random discard, or a die roll in FaB). This was written to make the result be deterministic if they undo then redo the same sequence of game actions while still being sufficiently unpredictable to be suitable for achieving card mixing.
Is it possible to manually seed the new function? The reason this all was done is because people were complaining about other people abusing undo to achieve a more desired random result (for example undo and redo a mulligan, or a random discard, or a die roll in FaB). This was written to make the result be deterministic if they undo then redo the same sequence of game actions while still being sufficiently unpredictable to be suitable for achieving card mixing.
I updated the code to perform the initial shuffle (before the start of the game) using the random_int
function for better randomness. Subsequent shuffles will be done using mt_rand
with a seed to allow undo operations.
I think there's a very subtle bug here; the problem is that randomSeeded is true both on the initial shuffle, and also for all calls to GetRandom after the first one while processing the same gamestate. So it would only respect the undo invariance if no more than one random effect is done during that gamestate processing.
I think there's a very subtle bug here; the problem is that randomSeeded is true both on the initial shuffle, and also for all calls to GetRandom after the first one while processing the same gamestate. So it would only respect the undo invariance if no more than one random effect is done during that gamestate processing.
I got your point and I updated the code to use random_int
only on the initial shuffle.
Improved randomness when shuffling the deck
mt_rand
torandom_int
.random_int
is better thanmt_rand
in PHP for higher randomness because it uses a cryptographic random number generator, providing stronger unpredictability.mt_rand
uses the Mersenne Twister algorithm, which is not suitable for cryptographic purposes. Regarding seeds,random_int
relies on sources like /dev/urandom or CryptGenRandom, ensuring better randomness without manual seeding.