vendredi 26 décembre 2014

Random value in objective c gives incorrect numbers

I need to get random float values in range [-1, 1].



CGFloat max = 1;
CGFloat min = -1;


I use following code:



((float)arc4random()/RAND_MAX)*(max-min)+min


But i get value between -1.007 to 2.879 and so on. Where i have a problem. Thank you.





Aucun commentaire:

Enregistrer un commentaire