Simple Random Vector Function Returns Same Direction More Than Once
So I made this simple function to return a random vector of magnitude 1 using pygame, basically a random vector that is then normalized (giving a direction). However, when I run a
Solution 1:
An alternative solution is to generate a random angle in range [0, 2*PI]. Compute the vector from the angle:
angle = random.uniform(0, math.PI*2)
vector = Vector2(math.cos(angle), math.sin(angle))
or
vector = Vector2(1, 0).rotate_rad(random.uniform(0, math.PI*2))
Post a Comment for "Simple Random Vector Function Returns Same Direction More Than Once"