Fix rand function