fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void foo(void) {
  6. float xmax = 200, ymax = 200, xmin = 0, ymin = 0;
  7. float xo1, yo1, xo2, yo2;
  8. int /*metadecampo, */metadecampo1, metadecampo2;
  9. int k,j,l,m;
  10. char configposicoesaleat = 's';
  11.  
  12. if (configposicoesaleat == 's' || configposicoesaleat == 'S') {
  13. k = (int)(xmax); //converte o float do xmax para um inteiro
  14. j = (int)(ymax); //converte o float do ymax para um inteiro
  15. l = (int)(xmin);
  16. m = (int)(ymin);
  17.  
  18. metadecampo1 = (xmin + xmax) / 2;
  19. metadecampo2 = (xmin + xmax) / 2;
  20.  
  21. xo1 = (float)(l + (rand() % metadecampo1)); // cria uma posicao em X aleator
  22. yo1 = (float)(m + (rand() % j)); // cria uma posicao em Y aleatoria desde o
  23. xo2 = (float)(metadecampo2 + (rand() % k)); // cria uma posicao em X aleator
  24. yo2 = (float)(m + (rand() % j)); // cria uma posicao em Y aleatoria desde o
  25.  
  26. printf("%f %f %f %f\n", xo1, yo1, xo2, yo2);
  27. }
  28. }
  29.  
  30. int main(void) {
  31. srand(time(0));
  32. foo();
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
14.000000 77.000000 227.000000 129.000000