marceloedreiPJ
cara é so vc mandar randomizar de 0 a 90 e somar 10 ao resultado…
int numero = r.nextInt(90);
numero=+10;
blz 
[/code]
_g4br1elPJ
ah ta… mas eu quero que ele gere numeros a partir de 10 até 100.
e ai ?
matheusPJ
( int ) ( 10 + Math.random() * 100 )
spierPJ
acho que a resposta é juntar as dicas do matheus com a do marceloedrei:
( int ) ( 10 + Math.random() * 90 )
ou, por partes:
int ate90 = ( Math.random() * 90 );
// mas não eh de 0 a 90
// então soma 10: se tinha dado 1 (de 0 a 90) + 10 = 11
// se tinha dado 89(de 0 a 90) + 10 = 99
// mas não acontecerah 95 (pois era de 0 a 90) + 10 = 105
ate90 += 10;
_g4br1elPJ
maviPJ
public class Test {
public static void main(String [] argvs) {
System.out.println(rand(5, 10) + "\t" + rand(5, 10) + "\t" + rand(5, 10));
System.out.println(rand(0, 1) + "\t" + rand(0, 1) + "\t" + rand(0, 1));
System.out.println(rand(1, 1) + "\t" + rand(1, 1) + "\t" + rand(1, 1));
}
static int rand(int Str, int End) {
return (int) Math.ceil(Math.random() * (End - Str + 1)) - 1 + Str;
}
}
Output:
C:\classes>java Test
7 5 5
0 0 0
1 1 1
Código:
static int rand(int Str, int End) {
return (int) Math.ceil(Math.random() * (End - Str + 1)) - 1 + Str;
}
Melhorou?
hipersoftPJ
É só galibar a solução do marcelodelrei:
int numero = r.nextInt(91);
numero=+10;