fix defect for rand function