Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void permute(int ia_urn2[], int i_urn2_depth, int i_NP, int i_avoid, int ia_urn1[]) {
- int k = i_NP;
- int i_urn1 = 0;
- int i_urn2 = 0;
- for (int i = 0; i < i_NP; i++)
- ia_urn1[i] = i; /* initialize urn1 */
- i_urn1 = i_avoid; /* get rid of the index to be avoided and place it in position 0. */
- while (k > i_NP - i_urn2_depth) { /* i_urn2_depth is the amount of indices wanted (must be <= NP) */
- ia_urn2[i_urn2] = ia_urn1[i_urn1]; /* move it into urn2 */
- ia_urn1[i_urn1] = ia_urn1[k-1]; /* move highest index to fill gap */
- k = k - 1; /* reduce number of accessible indices */
- i_urn2 = i_urn2 + 1; /* next position in urn2 */
- i_urn1 = static_cast<int>(::unif_rand() * k); /* choose a random index */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement