VOOZH about

URL: https://www.geeksforgeeks.org/r-language/create-random-deviates-of-uniform-distribution-in-r-programming-runif-function/

⇱ Create Random Deviates of Uniform Distribution in R Programming - runif() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create Random Deviates of Uniform Distribution in R Programming - runif() Function

Last Updated : 12 Jul, 2025

runif() function in R Language is used to create random deviates of the uniform distribution.

Syntax

runif(n, min, max)

Parameters:

  • n: represents number of observations.
  • min, max: represents lower and upper limits of the distribution. 

Example 1:

In this example, we are generating a uniform distribution of 20 random numbers between -1 and 1 using the runif() function in R. The resulting values are evenly distributed across the specified range and are printed for inspection.

Output:

[1] 0.90453974 -0.97083088 0.83531295 0.19008941 0.52278078 -0.75730955
[7] 0.21659920 -0.26621211 0.11967620 0.42081991 0.75518470 -0.41519833
[13] -0.03734007 0.57365077 0.76156708 0.97314141 -0.41957919 -0.08910355
[19] 0.29047038 -0.67069856

Example 2:

In this example, we are generating 10,000 random values from a uniform distribution between -5 and 5, and visualizing them with a histogram. We also overlay the theoretical probability density function to illustrate how the generated data aligns with the expected uniform distribution.

Output:

👁 Image
Comment
Article Tags:

Explore