5
$\begingroup$

I want to generate 8 random variables (in reality to form 4 complex numbers) such that the sum of the 8 variables squared is equal to unity. The aim of generating such numbers is to perform a quantum simulation of 4 qubits (thus the 8 parameters). I've been trying to use RandomVariate[NormalDistribution[]], but I'm not quite sure how to satisfy the constraint previously described.

$\endgroup$
1
  • 1
    $\begingroup$ If you needed to do this by hand (and not with Carl's answer), the approach is similar. Just think of a circle. You randomly choose an angle [0,2Pi] and then you calculate the point on the circle with {Cos[phi],Sin[phi]}. This automatically has your condition. Now you extend this into 8 dimensions. $\endgroup$
    – halirutan
    Commented May 31, 2018 at 16:12

1 Answer 1

6
$\begingroup$

You can use RandomPoint of a Sphere:

SeedRandom[1]
RandomPoint[Sphere[{0,0,0,0,0,0,0,0}]]
Norm @ %

{0.218453, 0.184026, 0.117791, 0.285912, 0.694608, 0.304419, 0.0587873, \ 0.494151}

1.

$\endgroup$
1
  • $\begingroup$ RandomPoint @ Sphere @ 8 is shorter. $\endgroup$
    – kglr
    Commented Jun 1, 2018 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.