Bonjour a tous
Je voudrais un float aléatoire entre 2 float.
J'y arrive comme cela mais c'est idiot d'utiliser des int pour avoir des float.J'ai tenté truc du genre?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 private float randRange(int min, int max) { Random r = new Random(); int x = min + r.nextInt(max - min); float res = (float) x; return res; }
mais j'ai une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 private float randRange(float min, float max) { Random r = new Random(); float x = min + r.nexFloat(max - min); return res; }
La méthode nextFloat() du type Random ne s'applique pas aux arguments
(float)
comment faire?
++
Partager