To generate random numbers from a normal distribution, use the “rnorm()” function. It generates random numbers from a normal, continuous probability distribution with a bell-shaped curve.
Example 1
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
In the function, mean, and sd are optional arguments you can specify based on your requirements.
Use the following code to generate 10 random numbers from a normal distribution with a mean of 40 and a standard deviation of 20.
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
To create a histogram, use the hist() function and provide the generated random numbers.
set.seed(99)
normal_dist_random_nums <- rnorm(10, mean = 40, sd = 20)
hist(normal_dist_random_nums)
Output
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
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.