fix randomize and infinite loop bug