Changed randomization algorithm