title: How can I use the random module in python turtle?
body: <p>I'm trying to make a game like the original snake and I want the "food" to go to random places but I'm not really sure how to get it to work with it in a class. There are some other errors in the code but want to focus on the player and the food right now.</p>
  
  <pre><code>import turtle
  import random
  """-------"""
  t=turtle.Turtle()
  s=turtle.Screen()
  cube=turtle.Turtle
  """------------"""
  WIDTH, HEIGHT=300, 300
  DISTANCE=5
  """--------------"""
  s.setup(WIDTH,HEIGHT)
  """------------"""
  t.width(1)
  s.bgcolor("dark green")
  """-----------------"""
  class Border():
      def check():
          x, y = t.position()
          if not -WIDTH / 2 &lt; x &lt; WIDTH / 2 or not -HEIGHT / 2 &lt; y &lt; HEIGHT / 2:
              t.undo() # undo error
              t.speed(0)
              t.left(180) # turn around
              t.forward(10) # redo movement but in new direction
              t.speed(3)
  """-------------"""
  randint=random.randint
  x=random.randint(cube.xcor, 0)
  y=random.randint(0,cube.ycor)
  """---------------"""
  class Food():
      def block():
          cube.color("red")
          for i in range(4):
              cube.goto(x, -x, y, -y)
              cube.begin_fill()
              cube.forward(20)
              cube.right(90)
              cube.end_fill()
  """---------------"""
  class Player():
      def move_up():
          player=False
          while player==False:
              for i in range(1):
                  t.forward(DISTANCE)
                  t.clear()
      def move_left():
          t.speed(0)
          t.left(90)
          t.speed(3)
      def move_right():
          t.speed(0)
          t.right(90)
          t.speed(3)
  """------------"""
  collistion_check=Border()
  player1=Player()
  s.onkey(Player.move_up,"up")
  s.onkey(Player.move_left,"left")
  s.onkey(Player.move_right,"right")
  s.listen()
  </code></pre>