Advertisement
SrJefers_Loading

generador

Feb 28th, 2016
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. ofstream dato("Data.txt", ios::app | ios::out);
  2. if (dato.fail())
  3. {
  4. cout << "Error al crear el archivo :(";
  5. }
  6. else
  7. {
  8. srand(time(0)); // iniciando la semilla aleatoria
  9.  
  10. // Formula a + rand() % (b-a+1)
  11.  
  12. // eligiendo 15 numeros aleatorios distintos entre 1 y 50
  13. for (ie = 0; ie<500; ie++)
  14. {
  15. // Genera numero aleatorio
  16. int num = 1 + rand() % 500;
  17.  
  18. if (ie>0)
  19. {
  20. // Verifica si no se ha generado antes
  21. for (je = 0; je < ie; je++)
  22. if (num == vectore[je])
  23. {
  24. num = 1 + rand() % 500;
  25. je = -1;
  26. }
  27. }
  28.  
  29. vectore[ie] = num;
  30. dato << vectore[ie] << endl;
  31. }
  32. dato.close();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement