URGENTE - Números randômicos

Como eu faço pra q nesse código os numeros não se repitam, por favor ajuda.

[code]public void gerarNumero(){

/**aki vai ser gerado os numeros principais
*veja q esta sendo setado o nome em cada Label*/
    int x = 0 + (int)(Math.random() * 11);
    jLabel14.setText(""+x);
    int y = 0 + (int)(Math.random() * 11);
    jLabel15.setText(""+y);

//gera umas das quatro alternativas para ser comparadas no if
int letra = 1 + (int)(Math.random()*4);

//aki ele somara os dois numeros gerados
//Resposta correta
    setResposta(x + y);


//respostas aleatorias
 a = 0 + (int)(Math.random() * 21);
 b = 0 + (int)(Math.random() * 21);
 c = 0 + (int)(Math.random() * 21);
 d = 0 + (int)(Math.random() * 21);[/code]

Cara…
Faz 1 favor pro guj:
NÃO DUPLIQUE TÓPICOS !

o que você não quer que repita?
o x? o y?
o a? o b? o c? o d?
Explica direito…

[code] a = 0 + (int)(Math.random() * 21);
b = 0 + (int)(Math.random() * 21);

while (a==b) {
b = 0 + (int)(Math.random() * 21);
}

  c = 0 + (int)(Math.random() * 21);  

while (c==a || c==b) {
c = 0 + (int)(Math.random() * 21);
}

  d = 0 + (int)(Math.random() * 21);  

while (d==a ||d==b || d==c) {
d = 0 + (int)(Math.random() * 21);
}[/code]

a, b, c, d

da forma que vc falou o a, b, c e o d ainda se repetem, acabei de testar

Quase certeza que já vi incontáveis respostas para essa questão e se ainda não adiantou … well …
Uma das possíveis soluções:

[code]public class RandomNumbers {

private List<Integer> numerosGerados = new ArrayList<Integer>();
private Random gerador = new Random();
private int range;

public RandomNumbers(int range) {
	this.range = range;
}

public int gerarNumeroAleatorio() {

	int retorno;
	retorno = gerador.nextInt(range);
	if (numerosGerados.contains(retorno))
		return -1;
	else {
		numerosGerados.add(retorno);
		return retorno;
	}

} // gerarNumeroAleatorio

public static void main(String[] args) {
	RandomNumbers gerador = new RandomNumbers(10);
	int numeroGerado;
	for (int i = 0; i < 100; i++) {
		numeroGerado = gerador.gerarNumeroAleatorio();
		if (numeroGerado != -1)
			System.out.println(numeroGerado);
	} // for
} // main

} // class[/code]

a questão é não tem como mudar meu código pra ele funcionar?? se num tiver falem.
:?

[code]public static void main(String[] args){
final int MAXIMO = 20; //Intervalo de números possíveis será de 0 a MÁXIMO
int a, b, c, d;

	List<Integer> lista = new ArrayList<Integer>(MAXIMO);
	
	for(int i = 0; i < MAXIMO; i++){
		lista.add(i);
	}
	
	Collections.shuffle(lista);
	
	a = lista.get(0);
	b = lista.get(1);
	c = lista.get(2);
	d = lista.get(3);
	
	System.out.println("a = " + a);
	System.out.println("b = " + b);
	System.out.println("c = " + c);
	System.out.println("d = " + d);
	
}[/code]

ou

[code]public static void main(String[] args){
final int MAXIMO = 20; //Intervalo de números possíveis será de 0 a MÁXIMO
int a, b, c, d;

	Set<Integer> numeros = new LinkedHashSet<Integer>(MAXIMO);
	while(numeros.size() != 4){
		numeros.add((new Random()).nextInt(MAXIMO));
	}
	
	Iterator<Integer> i = numeros.iterator();
	a = i.next();
	b = i.next();
	c = i.next();
	d = i.next();
	
	System.out.println("a = " + a);
	System.out.println("b = " + b);
	System.out.println("c = " + c);
	System.out.println("d = " + d);
	
	
}[/code]

ok?

[quote=Rooney]a questão é não tem como mudar meu código pra ele funcionar?? se num tiver falem.
:?
[/quote]

… … … pois é, o que eu propus foi um método que você poderia usar no seu código. Basta mandar o método gerar os números no lugar dos Math.random

Olá

URGENTE - Números randômicos?

Tentou 193?

[]s
Luca