Advertisement
MagicWinnie

Points generation script

Mar 17th, 2023 (edited)
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import random
  2.  
  3. output = ''
  4. DEVIATION = 0.1
  5. M = 32
  6. N = 8
  7.  
  8. coeffs = [random.random() * 10 - 5 for _ in range(N + 1)]
  9. F = lambda x: sum(coeffs[i] * x ** i for i in range(N + 1))
  10.  
  11. points = []
  12. for _ in range(M):
  13.     x = random.random() * random.random() * 2 - 1
  14.     y = F(x)
  15.     points.append((x, y))
  16. max_x = max(points, key=lambda x: abs(x[0]))[0]
  17. max_y = max(points, key=lambda x: abs(x[1]))[1]
  18.  
  19. output += f"{M}\n"
  20. for i in range(M):
  21.     x = points[i][0] + random.random() * max_x * DEVIATION - max_x * DEVIATION / 2
  22.     y = points[i][1] + random.random() * max_y * DEVIATION - max_y * DEVIATION / 2
  23.     output += f"{round(x, 2)} {round(y, 2)}\n"
  24. output += f"{N}"
  25.  
  26. with open("points.txt", "w") as outfile:
  27.     outfile.write(output)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement