Advertisement
JuanTorres

Untitled

Feb 6th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. srand(time(0)); // iniciando la semilla aleatoria
  2.  
  3. // Formula a + rand() % (b-a+1)
  4.  
  5. // eligiendo 15 numeros aleatorios distintos entre 1 y 50
  6. for(i=0;i<15;i++)
  7. {
  8.     // Genera numero aleatorio
  9.     int num = 1 + rand()%50;
  10.  
  11.    if(i>0)
  12.    {
  13.       // Verifica si no se ha generado antes    
  14.       for(j=0; j < i; j++)    
  15.           if(num==vector[j])
  16.           {
  17.              num = 1 + rand()%50;
  18.              j=-1;                          
  19.           }
  20.     }
  21.  
  22.     vector [ i ] =num;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement