Advertisement
msfz751

function that returns nothing, RcppArmadillo

Aug 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.86 KB | None | 0 0
  1. void permute(int ia_urn2[], int i_urn2_depth, int i_NP, int i_avoid, int ia_urn1[]) {
  2.     int k = i_NP;
  3.     int i_urn1 = 0;
  4.     int i_urn2 = 0;
  5.     for (int i = 0; i < i_NP; i++)
  6.         ia_urn1[i] = i;                    /* initialize urn1 */
  7.  
  8.     i_urn1 = i_avoid;                      /* get rid of the index to be avoided and place it in position 0. */
  9.     while (k > i_NP - i_urn2_depth) {      /* i_urn2_depth is the amount of indices wanted (must be <= NP) */
  10.         ia_urn2[i_urn2] = ia_urn1[i_urn1]; /* move it into urn2 */
  11.         ia_urn1[i_urn1] = ia_urn1[k-1];    /* move highest index to fill gap */
  12.         k = k - 1;                         /* reduce number of accessible indices */
  13.         i_urn2 = i_urn2 + 1;               /* next position in urn2 */
  14.         i_urn1 = static_cast<int>(::unif_rand() * k);   /* choose a random index */
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement