i need to generate a random number between -0.5 and 0.5.
ive tried a solution on stack overflow by the user anthony pegram. i have modifyed it a bit ( i need the method to be called and used in a console.write line)
public static float nextfloat()
{
Random random = new Random();
double val = random.NextDouble();
val -= 0.5;
return float.MaxValue * (float)val;
}
by trying this i get numbers which are beyond -0.5 and 0.5 i get things like
1.7 1.005 etc
Aucun commentaire:
Enregistrer un commentaire