R runif and rnorm producing same random numbers with vector operation
<p>I am trying to generate random data with R's <code>runif</code> and <code>rnorm</code> functions, where these functions are supposed to add some "noise" to the generated data. However, they are producing the same random number when I apply them as part of a vector addition operation.</p>

<p>Below is an example where <code>x</code> is an independent variable. I would to generate <code>y</code> and <code>z</code>, which are dependent output variables with a little "noise" added to them by the random number generators. The noise is supposed to change randomly with every new value of <code>x</code>. </p>

<pre><code>x &lt;- seq(1:10)
y &lt;- x + runif(1)
z &lt;- x + rnorm(1,mean=2, sd=0.5)
df &lt;- data.frame(x, y, z)
df
#     x         y        z
# 1   1  1.364842  3.10679
# 2   2  2.364842  4.10679
# 3   3  3.364842  5.10679
# 4   4  4.364842  6.10679
# 5   5  5.364842  7.10679
# 6   6  6.364842  8.10679
# 7   7  7.364842  9.10679
# 8   8  8.364842 10.10679
# 9   9  9.364842 11.10679
# 10 10 10.364842 12.10679
</code></pre>

<p>As seen above, each random number generator is creating identical values. Why is this happening? <strong>How can I fix the problem so that they generate different random numbers every time they are added to the <code>x</code> variable in the vector addition operation?</strong></p>

<p>Here is proof that the two functions are working correctly. I did not set any seed value.</p>

<pre><code>runif(1)
# [1] 0.05202364
runif(1)
# [1] 0.02315487
rnorm(1,mean=2, sd=0.5)
# [1] 1.714753
rnorm(1,mean=2, sd=0.5)
# [1] 1.369988
</code></pre>