triangular distribution for creating four momentum vector

244 views Asked by At

In my problem I am to create a base class to represent a four vector (a concept in physics involving a four dimensional vector) then create a derived class specifically to represent the four momentum of a particle which inherits from the base class. I have been supplied a small piece of code to use to generate a 'random' x y and z component of the momentum magnitude. The code is as follows

#include <cstdlib>
double triangular(double momentum){
    double x, y;
    do{
        x = momentum*rand()/RAND_MAX;
        y = x/momentum;
    } while (1.0*rand()/RAND_MAX > y);
    return x;
}

It is said in my problem that this code is supposed to generate the magnitude, and then randomly split into x, y and z components. This code returns a single value and so I cannot see how it is doing what it says in the problem. Could someone help me to understand what this code is doing and how it could be used to create three components of a momentum magnitude. Thank you kindly.

0

There are 0 answers