dimanche 1 octobre 2017

Random.nextInt returns contiguous same-value integers (frequently)

I see results like the below when running Random.nextInt(3) 81 times:

200010202002112102222211012021020111220022001021101222222022210222220100000100010

Notice the large contiguous blocks: 000, 22222, 111, 222222, 222, 22222, 00000, 000.

Intuitively, the sequence doesn't seem naturally / "real-world coin flip" random.

For example, to achieve 6x contiguous 2s there's only a 0.4% chance (AFAIK) and for 5x contiguous values there's a 1.2% chance ... so it seems unlikely I should keep seeing patterns like this in the output.

Would this happen in the real-world with a 3-sided coin? Or is this an expected deviation from "true random" when using Java's Random.nextInt(exclusiveMax) method?




Aucun commentaire:

Enregistrer un commentaire