Following data samples you provide:
possibleColours: 65536,
i: 20
You increment sizes
here:
sizes *= possibleColours;
so already on second iteration you have (applying sample data provided in place):
i sizes possibleColours
BigInteger index = (20/65536) % 65536;
where 20/65536 == 0
as you devide integers
, so result of devision is also integer
itself.
After we get:
BigInteger index = 0 % 65536;
, so index==0
.
That means after first iteration you will get always 0
, what your are experiencing actually.