Updated randomize function.