Algorytm niedeterministyczny, to taki, którego działanie nie jest z góry ustalone. W poniższym kodzie kąt jest losowany, więc każde kolejne uruchomienie programu będzie wyglądać trochę inaczej.
import turtle
import random
t = turtle.Turtle()
t.speed(0) # 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest
while(True):
t.forward(50)
x,y = t.pos()
if(x<-200):
t.setheading(random.randint(280,440))
if(x>200):
t.setheading(random.randint(100,260))
if(y<-200):
t.setheading(random.randint(10,170))
if(y>200):
t.setheading(random.randint(190,330))