Gerando numero random de um intervalo a outro! ta dando pau!

tipo, quero gerar um numero random do intervalo 10, a 100… ai coloco

random r = new random();
int numero = (int) 10 + r.nextInt() * 100;

ele gera numeros maiores que 100 tb…
e se eu fizer:
int numero = (int) 10 + r.nextInt(101);
ele tb continua gerando numeros maiores que 100.

ajuda ae

cara é so vc mandar randomizar de 0 a 90 e somar 10 ao resultado…

int numero = r.nextInt(90);
numero=+10;

blz :grin:

[/code]

ah ta… mas eu quero que ele gere numeros a partir de 10 até 100.
e ai ?

( int ) ( 10 + Math.random() * 100 )

acho que a resposta é juntar as dicas do matheus com a do marceloedrei:

( int ) ( 10 + Math.random() * 90 )

ou, por partes:

[code]
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;

                           [/code]

ta complicado!

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?

É só galibar a solução do marcelodelrei:

int numero = r.nextInt(91); 
numero=+10;