If you can use the new c++11 standard, it is easy to create gaussian distributed random numbers. Then you can use the fact that three 1-dimensional gaussian numbers makes one 3-dimensional gaussian coordinate, which is uniformly distributed on a sphere of constant radius (the radius is gaussian distributed). If you want the coordinates only on a specific radius you have to normalize your coordinates. Here's how you can do it:
#include <iostream>
#include <random>
#include <cmath>
using namespace std;
int main (int argC, char* argV[])
{
//Create random generator
mt19937 rnd;
//Create Gaussian distribution
normal_distribution<double> normDist ( 0.0, 1.0 );
//Seed random generator
rnd.seed(time(NULL));
const double sphereRadius = 1;
//Create 3 Gauss Random Numbers
double rndArray[3];
double rndSqrSum = 0;
for ( uint i = 0; i < 3; i++ )
{
rndArray[i] = normDist( rnd );
rndSqrSum += rndArray[i] * rndArray[i];
}
//Calculate Faktor to get a Sphere of radius sphereRadius
double faktor = sphereRadius / sqrt( rndSqrSum ) ;
//The random Coordinates then are:
double x = rndArray[0]*faktor;
double y = rndArray[1]*faktor;
double z = rndArray[2]*faktor;
cout << "Koordinates are: " << endl << "x: " << x << endl << "y: " << y << endl << "z: " << z << endl << "Radius is: " << sqrt(x*x+y*y+z*z) << endl;
}
For your application probably not needed but useful though, this method can be used for arbitrary dimensions, eg. 20 dimensional problems.