Generate Data sets of same Random Values in R Programming - set.seed() Function Last Updated : 30 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The set.seed() function in R ensures that random number generation is consistent across different sessions, allowing for identical results each time the code is executed. This is particularly important when sharing code with others or when results need to be verified.Syntax: set.seed(n)Where:n: seeds for repeatable data sets Why set.seed() is requiredIn R, the set.seed() function is not mandatory for all analyses. However, it is recommended to use it in some instances. We know that functions like rnorm(), runif(), and sample() produce different results each time they are called, setting a seed ensures that the sequence of random numbers can be reproduced. This allows for:Reproducibility: Ensuring that analyses can be repeated with the same data and results.Debugging: Identifying and fixing issues in code by providing consistent outputs.Collaboration: Allowing others to verify results by running the same code with the same data.Example: Creating Reproducible Random Data SetsIn this example we will use the set.seed() to generate reproducible random data. By setting the seed to 123, the sequence of random numbers generated by rnorm(10) will be the same each time this code is executed. R set.seed(123) random_data <- rnorm(10) print(random_data) Output:[1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774 1.71506499 [7] 0.46091621 -1.26506123 -0.68685285 -0.44566197Verifying ReproducibilityTo confirm that the random number generation is reproducible, we can compare two data sets generated with the same seed using the identical() function. R set.seed(123) dt_1 <- rnorm(10) set.seed(123) dt_2 <- rnorm(10) identical(dt_1, dt_2) Output:TRUESince both data sets are identical, this confirms that setting the seed ensures reproducibility.In this article, we will discuss how we Generate Data sets of the same Random Values in the R Programming Language using set.seed() Function. Comment More info N nidhi_biet Follow Improve Article Tags : R Language R Vector-Function Explore R Tutorial | Learn R Programming Language 4 min read IntroductionR Programming Language - Introduction 4 min read Interesting Facts about R Programming Language 4 min read R vs Python 5 min read Environments in R Programming 3 min read Introduction to R Studio 4 min read How to Install R and R Studio? 4 min read Creation and Execution of R File in R Studio 5 min read Clear the Console and the Environment in R Studio 2 min read Hello World in R Programming 2 min read Fundamentals of RBasic Syntax in R Programming 3 min read Comments in R 3 min read R-Operators 5 min read R-Keywords 2 min read R-Data Types 5 min read VariablesR Variables - Creating, Naming and Using Variables in R 5 min read Scope of Variable in R 5 min read Dynamic Scoping in R Programming 5 min read Lexical Scoping in R Programming 4 min read Input/OutputTaking Input from User in R Programming 7 min read Printing Output of an R Program 4 min read Print the Argument to the Screen in R Programming - print() Function 2 min read Control FlowControl Statements in R Programming 4 min read Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch 3 min read Switch case in R 2 min read For loop in R 5 min read R - while loop 5 min read R - Repeat loop 2 min read goto statement in R Programming 2 min read Break and Next statements in R 3 min read FunctionsFunctions in R Programming 5 min read Function Arguments in R Programming 4 min read Types of Functions in R Programming 6 min read Recursive Functions in R Programming 4 min read Conversion Functions in R Programming 4 min read Data StructuresData Structures in R Programming 4 min read R Strings 6 min read R-Vectors 4 min read R-Lists 6 min read R - Array 7 min read R-Matrices 10 min read R-Factors 4 min read R-Data Frames 6 min read Object Oriented ProgrammingR-Object Oriented Programming 7 min read Classes in R Programming 3 min read R-Objects 3 min read Encapsulation in R Programming 3 min read Polymorphism in R Programming 6 min read R - Inheritance 7 min read Abstraction in R Programming 3 min read Looping over Objects in R Programming 5 min read S3 class in R Programming 8 min read Explicit Coercion in R Programming 3 min read Error HandlingHandling Errors in R Programming 3 min read Condition Handling in R Programming 5 min read Debugging in R Programming 3 min read Like