utils.py 342 B

12345678910111213141516171819
  1. from random import randint as rand
  2. def randbool(r, mxr):
  3. t = rand(0, mxr)
  4. return (t <= r)
  5. def randcell(w, h):
  6. tw = rand(0, w)
  7. th = rand(0, h)
  8. return (th, tw)
  9. #
  10. def randcell2(x, y, w, h):
  11. moves = [(-1, 0), (0, 1), (1, 0), 0, -1]
  12. t = rand(0, 3)
  13. dx, dy = moves[t][0], moves[t][1]
  14. return (x + dx, y + dy)