function is too slow, must use a shuffled array