How to generate the same set of random numbers in R
Some times in testing, it is necessary to generate the same set of random numbers every time the program is run. Use the following methods to achieve it.
Reuse
Save the same set of random numbers and use it.
# Use the dist variable every time you need the same distribution
> dist = rnorm(100, mean=100, sd=10 )
SET.SEED ( )
Use can use the same seed to get the same distribution every time you run rnorm
> set.seed(100)
> rnorm(100,mean=100,sd=10)