// fill the given column with random doubles in the given range: [min, max)
// does not set the state of undefined
Matrix &Matrix::randCol(int c, double min, double max)
{

    for (int r=0; r<maxr; r++) {
        m[r][c] = randUnit()*(max-min) + min;
    }

    return *this;
}
glm::vec3 Mth::randInsideSphere(float radius) {
    float phi = randRange(0.0f, PI*2.0f);
    float costheta = randUnit();
    float u = rand01();

    float theta = acos(costheta);
    float r = radius * std::pow(u, 1.0f / 3.0f);
    return glm::vec3(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta))*r;
}
// fill with random doubles in the given range: [min, max)
Matrix &Matrix::rand(double min, double max)
{
    for (int r=0; r<maxr; r++) {
        for (int c=0; c<maxc; c++) {
            m[r][c] = randUnit()*(max-min) + min;
        }
    }

    defined = true;

    return *this;
}
glm::vec3 Mth::randOnUnitSphere() {
    float phi = randRange(0.0f, PI*2.0f);
    float costheta = randUnit();
    float theta = acos(costheta);
    return glm::vec3(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta));
}
glm::vec3 Mth::randInsideUnitCube() {
    return glm::vec3(randUnit(), randUnit(), randUnit());
}