fix shuffle to run in linear time