Skip to content

Instantly share code, notes, and snippets.

View jorgecarleitao's full-sized avatar

Jorge Leitao jorgecarleitao

  • Munin Data ApS
  • Lisboa, Portugal
View GitHub Profile
@jorgecarleitao
jorgecarleitao / gist:a7ef61d4d918ee8059d6
Created May 21, 2014 13:01
Generates a unitary random vector in D dimensions
std::vector<double> unitaryVector(unsigned int dimension)
{
std::vector<double> vector(dimension);
double norm = 0;
for (unsigned int d = 0; d < dimension; d++)
{
vector[d] = grandom(); // RNG call for a gaussian with mean=0 and sigma=1
norm += vector[d]*vector[d];
}
norm = sqrt(norm);