Generating random numbers a, b, c such that a^2 + b^2 + c^2 = 1

Viewed 1612

To do some simulations in Python, I'm trying to generate numbers a,b,c such that a^2 + b^2 + c^2 = 1. I think generating some a between 0 and 1, then some b between 0 and sqrt(1 - a^2), and then c = sqrt(1 - a^2 - b^2) would work.

Floating point values are fine, the sum of squares should be close to 1. I want to keep generating them for some iterations.

Being new to Python, I'm not really sure how to do this. Negatives are allowed.

Edit: Thanks a lot for the answers!

6 Answers
Related