def random_in_unit_disk(): p = Vec() while True: p.x = 2 * random() p.y = 2 * random() if Vec.dot(p, p) >= 1: break return p
def random_in_unit_sphere(): p = Vec() while True: p.x = 2 * random() - 1 p.y = 2 * random() - 1 p.z = 2 * random() - 1 if p.squared_length() < 1: break return p