Use mod instead of random.nextInt, which was very slow