added randomization code