void Shuffle(const RandomGenerator &rng, u_int *samp, u_int count, u_int dims) { for (u_int i = 0; i < count; ++i) { u_int other = rng.uintValue() % count; for (u_int j = 0; j < dims; ++j) swap(samp[dims*i + j], samp[dims*other + j]); } }
void LatinHypercube(const RandomGenerator &rng, float *samples, u_int nSamples, u_int nDim) { // Generate LHS samples along diagonal float delta = 1.f / nSamples; for (u_int i = 0; i < nSamples; ++i) for (u_int j = 0; j < nDim; ++j) samples[nDim * i + j] = (i + rng.floatValue()) * delta; // Permute LHS samples in each dimension for (u_int i = 0; i < nDim; ++i) { for (u_int j = 0; j < nSamples; ++j) { u_int other = rng.uintValue() % nSamples; swap(samples[nDim * j + i], samples[nDim * other + i]); } } }