Skip to content

Instantly share code, notes, and snippets.

@goldsborough
Created December 22, 2017 18:49
Show Gist options
  • Save goldsborough/75ee1802110eda71517cc33ea3c59a88 to your computer and use it in GitHub Desktop.
Save goldsborough/75ee1802110eda71517cc33ea3c59a88 to your computer and use it in GitHub Desktop.
const float two_pi = 2.0f * 3.14159265358979323846f;
for (int i = 0; i < kNumber; i += 16) {
for (int j = 0; j < 8; ++j) {
const float u1 = 1 - uniform[i + j];
const float u2 = uniform[i + 8 + j];
const float radius = std::sqrt(-2 * std::log(u1));
const float theta = two_pi * u2;
output[i + j] = radius * std::cos(theta);
output[i + 8 + j] = radius * std::sin(theta);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment