How to Generate Standard Normal Random Numbers in R

To generate standard normal random numbers in R, use the “rnorm()” function.

Example 1: Basic usage

Generate Normal Distribution Random Numbers

set.seed(99)

normal_dist_random_nums <- rnorm(10)

print(normal_dist_random_nums)

Output

 [1] 0.2139625 0.4796581 0.0878287 0.4438585 -0.3628379 0.1226740
 [7] -0.8638452 0.4896243 -0.3641169 -1.2942420

Example 2: Providing mean and sd

In this function, mean and sd are optional arguments you can specify based on your requirements.

Passing sd and mean

set.seed(99)

normal_dist_random_nums <- rnorm(900, mean = 30, sd = 60)
hist(normal_dist_random_nums)

Output

[1] 44.27925 49.59316 41.75657 48.87717 32.74324 42.45348 22.72310 49.79249
[9] 32.71766 14.11516

Example 3: Creating histogram

set.seed(99)

normal_dist_random_nums <- rnorm(10, mean = 40, sd = 20)
hist(normal_dist_random_nums)

Output

Creating a histogram based on normal distribution

I have used RStudio to show the plot using the hist() function.

Let’s see another example.

set.seed(99)

normal_dist_random_nums <- rnorm(900, mean = 30, sd = 60)

hist(normal_dist_random_nums)

Output

histogram of random normal distrubution numbers

That’s it.

Leave a Comment