I'm trying to generate a pair of random numbers between -1 and 1.
I can make it go negative OR positive...but not generate a random number for x and y that may turn out negative as well as positive. Below is what I have (it's a dart throw simulation game from a website). randx and randy are where the random number generation is happening to be used as the coordinates.
import turtle
import math
import random
def main():
fred = turtle.Turtle()
fred.up()
wn = turtle.Screen()
wn.setworldcoordinates(-1,-1,1,1)
numdarts = 10
for i in range(numdarts):
randx = random.random()
randy = random.random()
x = randx
y = randy
fred.goto(x,y)
fred.stamp()
wn.exitonclick()
main()
Aucun commentaire:
Enregistrer un commentaire