Updated randomization code