Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/03/2013, 03:50
Avatar de rgf1987
rgf1987
 
Fecha de Ingreso: diciembre-2012
Ubicación: Asturias
Mensajes: 269
Antigüedad: 12 años, 1 mes
Puntos: 22
Respuesta: Numeros Aleatorios no Repetidos

Tendrías que hacer un método comprobarNumero() que comprobase si ya has agregado el número al array me explico


Código JAVA:
Ver original
  1. public static int[] Sortear(){
  2.             int aleatorio[]=new int[6];
  3.             int numAgregar;
  4.             Random rand=new Random();
  5.             for(int i=0;i<6;i++){
  6.                 numAgregar = rand.nextInt(50);
  7.                 if(!comprobarNumero(numAgregar))
  8.                        aleatorio[i]=numAgregar;              
  9.             }          
  10.            
  11.             return aleatorio;
  12.            
  13.         }
  14.  
  15.          public boolean comprobarNumero(int num){
  16.                for(int i=0;i<(aleatorio.size() -1);i++){
  17.                        if(aleatorio[i]==num)
  18.                             return true;
  19.                }
  20.                return false;
  21.          }

La idea sería algo así, lo he programado aquí mismo así que igual no funciona bien jeje, pero la idea es esa.

Saludos!!