title: PDF/Tex-file produced by knitr contains different random numbers from those generated with same code in console
body: <p>Knitr is great at integrating text and output from code. The goal of using this is often called 'reproducible research'. Now when this research contains random numbers (e.g. for multiple imputations) then the key to reproducibility is the <code>set.seed</code> function in R.</p>
  <p>But somehow the two types of reproducible are not compatible.</p>
  <p>Look at the short Rnw-file below.</p>
  <pre><code>\documentclass{article}
  
  \begin{document}
  
  When I run the below chunck in the console I get (every time) the following numbers:
  
  $$8, 94, 96, 92, 99, 57, 44, 45, 35, 43, 44, 71$$
  
  However, when I run the enitre Rnw-program using the 'Compile pdf' button in Rstudio I get (every time) the following numbers:
  
  $$34, 97, 52, 68, 2, 57, 76, 20, 96, 68, 27, 29$$
  
  What number do \emph{you} get?
  
  &lt;&lt;minimalexample, results = 'markup'&gt;&gt;=
  set.seed(20200705)
  sample(seq(1, 100), 12, replace = T)
  @
  
  \end{document}
  </code></pre>
  <p>My questions are:</p>
  <ul>
  <li>How is this possible?</li>
  <li>Can we do something to get the same numbers in both ways of running the code?</li>
  <li>What numbers do you (the reader) get when running this program and/or only the chunck?</li>
  </ul>