mardi 9 août 2016

Why is Random.nextInt() %16 skewed while Random.nextInt(16) works perfectly fine?

I am writing a Bukkit plugin that treats snowballs as paintballs. When I accidentally used:

(byte) (random.nextInt() % 16)

instead of

(byte) (random.nextInt(16))

I noticed that lower numbers appeared way more than higher numbers. Why does that happen?

Ex: Before:

00010
01200
06001
30010
00502

Ex: After:

74108
73447
98956
17386
26574




Aucun commentaire:

Enregistrer un commentaire