Functions > Statistics > Probability Distributions > Example: Seed for Random Number Generation
  
Example: Seed for Random Number Generation
Use the Seed function to control the process of generating new sets of random numbers.
1. Use functions Seed and rnorm in a short program to generate identical sets of normally distributed random numbers for three iterations by resetting the Seed value.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
* 
The same set of random numbers is generated each time because the seed is set to 1.
SameNormal returns a matrix of three identical columns, one for each iteration.
2. Use functions hist and max to plot a histogram of the second random set with n_bins bins. Add a horizontal marker to show the maximum of the returned set.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
3. Modify the program to generate three different sets of normally distributed random numbers by incrementing the seed value with each iteration.
Click to copy this expression
* 
Now that the seed value changes with each iteration, each set of random numbers is unique.
Since iteration=0 of both programs starts with seed=1, column=0 of both returned matrices contain identical sets.
4. Extract the second data set from the returned matrix:
Click to copy this expression
5. Use function hist to generate a histogram of the random set with n_bins bins, then calculate its maximum.
Click to copy this expression
Click to copy this expression
6. Plot the histogram and use a horizontal marker to show its maximum:
Click to copy this expression