fork download
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. struct cpoint
  7. {
  8. double x, y;
  9. };
  10.  
  11. int main() {
  12. srand(time(0));
  13. int tmpValue;
  14. double sign;
  15. cpoint randomPoint;
  16. tmpValue = rand() % 1;
  17. if (tmpValue == 0)
  18. {
  19. sign = 1.0;
  20. }
  21. else
  22. {
  23. sign = -1.0;
  24. }
  25. randomPoint.x = sign*(rand()%10000+1)/10000.0;
  26.  
  27. tmpValue = rand() % 100 + 1;
  28. if (tmpValue >= 50)
  29. {
  30. sign = 1.0;
  31. }
  32. else
  33. {
  34. sign = -1.0;
  35. }
  36. randomPoint.y = sign*(rand()%10000+1)/10000.0;
  37. cout << tmpValue;
  38. cout << "sign : " << sign << endl;
  39. cout << "x : " << randomPoint.x << endl;
  40. cout << "y : " << randomPoint.y << endl;
  41. return 0;
  42. }
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
96sign : 1
x : 0.9469
y : 0.4666