un float random entre 2 float
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.
Code:
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;
} |
J'ai tenté truc du genre?
Code:
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;
} |
mais j'ai une erreur :
La méthode nextFloat() du type Random ne s'applique pas aux arguments
(float)
comment faire?
++