Modify randomize function