title: Issues with seed setting in parallelised foreach loop R
body: <p>I have a selection of tests I want to run in parallel. When I do this using foreach(), I get the expected output of 20 test - iteration pairs:</p>
  <pre><code>## Without seed
  require(data.table)
  require(foreach)
  require(iterators)
  require(doParallel)
  require(doRNG)
  
  numCores = 2
  registerDoParallel(numCores)
  
  iterations = 5
  num_tests = 2:5
  
  foreach( i = 1:iterations, .combine = 'rbind', .multicombine = TRUE, .inorder = FALSE ) %:%
    foreach( n = num_tests, .combine = 'rbind', .multicombine = TRUE, .inorder = FALSE ) %dopar% {
      
      ## Print iteration
      print(paste('Tests =',n,'Iteration =',i))
      
    }
  </code></pre>
  <p>Output:</p>
  <pre><code>result.1 &quot;Tests = 2 Iteration = 1&quot;
  result.2 &quot;Tests = 3 Iteration = 1&quot;
  result.3 &quot;Tests = 4 Iteration = 1&quot;
  result.4 &quot;Tests = 5 Iteration = 1&quot;
  result.1 &quot;Tests = 2 Iteration = 2&quot;
  result.2 &quot;Tests = 3 Iteration = 2&quot;
  result.3 &quot;Tests = 4 Iteration = 2&quot;
  result.4 &quot;Tests = 5 Iteration = 2&quot;
  result.1 &quot;Tests = 2 Iteration = 3&quot;
  result.2 &quot;Tests = 3 Iteration = 3&quot;
  result.3 &quot;Tests = 4 Iteration = 3&quot;
  result.4 &quot;Tests = 5 Iteration = 3&quot;
  result.1 &quot;Tests = 2 Iteration = 4&quot;
  result.2 &quot;Tests = 3 Iteration = 4&quot;
  result.3 &quot;Tests = 4 Iteration = 4&quot;
  result.4 &quot;Tests = 5 Iteration = 4&quot;
  result.1 &quot;Tests = 2 Iteration = 5&quot;
  result.2 &quot;Tests = 3 Iteration = 5&quot;
  result.3 &quot;Tests = 4 Iteration = 5&quot;
  result.4 &quot;Tests = 5 Iteration = 5&quot;
  </code></pre>
  <p>However, when I attempt to add a step to this loop that sets a random seed as described in the doRNG vignette, I get a different number of tests per iteration (14 test-iteration pairs):</p>
  <pre><code>## With seed
  numCores = 2
  registerDoParallel(numCores)
  
  iterations = 5
  num_tests = 2:5
  rng &lt;- RNGseq( iterations * (iterations+1) / 2, 1234)
  
  foreach( i = 1:iterations, .combine = 'rbind', .multicombine = TRUE, .inorder = FALSE ) %:%
    foreach( n = num_tests, r = rng[(i-1)*i/2 + 1:i], .combine = 'rbind', .multicombine = TRUE, .inorder = FALSE ) %dopar% {
      
      ##Set seed
      rngtools::setRNG(r)
      
      ## Print iteration
      print(paste('Tests =',n,'Iteration =',i))
      
    }
  </code></pre>
  <p>Output:</p>
  <pre><code>result.1 &quot;Tests = 2 Iteration = 1&quot;
  result.1 &quot;Tests = 2 Iteration = 2&quot;
  result.2 &quot;Tests = 3 Iteration = 2&quot;
  result.1 &quot;Tests = 2 Iteration = 3&quot;
  result.2 &quot;Tests = 3 Iteration = 3&quot;
  result.3 &quot;Tests = 4 Iteration = 3&quot;
  result.1 &quot;Tests = 2 Iteration = 4&quot;
  result.2 &quot;Tests = 3 Iteration = 4&quot;
  result.3 &quot;Tests = 4 Iteration = 4&quot;
  result.4 &quot;Tests = 5 Iteration = 4&quot;
  result.1 &quot;Tests = 2 Iteration = 5&quot;
  result.2 &quot;Tests = 3 Iteration = 5&quot;
  result.3 &quot;Tests = 4 Iteration = 5&quot;
  result.4 &quot;Tests = 5 Iteration = 5&quot;
  </code></pre>
  <p>I'm looking for a way to set seeds in parallel, nested foreach() loops with the correct number of iterations. Any ideas?</p>