// initialize the permuations to generate void Simplex::initPerm() { RNG rng; rng.setSeed(m_seed); // each element from 0-255 inside the permutations, no duplicates for(int i = 0; i < 256; i++) perm[i] = i; // shuffle the array for(int i = 255; i > 0; i--) { int j = rng.getInt(0, i+1); // i+1 since the rng.getInt is not inclusive int hold = perm[i]; perm[i] = perm[j]; perm[j] = hold; } // copy the array to the top half // uses more memory but makes things easier for(int i = 256; i < 512; i++) perm[i] = perm[i&255]; }