The “set.seed” Function in R

  • Package: Base R (No specific package, it’s a built-in function)

  • Purpose: To set the seed for the random number generator, ensuring reproducibility of random processes.

  • General Class: Random Number Generation

  • Required Argument(s):

    • seed: An integer specifying the seed value.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example usage
    set.seed(123)

    # Generate three random numbers
    random_numbers_1 <- runif(3)

    # Reset the seed
    set.seed(123)

    # Generate the same three random numbers
    random_numbers_2 <- runif(3)

    print(random_numbers_1)
    print(random_numbers_2)

  • In this example, set.seed is a built-in function in base R, and it is used to set the seed for the random number generator. This ensures the reproducibility of random processes, allowing you to obtain the same sequence of random numbers across multiple runs. The seed argument is required and represents the integer value to use as the seed. There are no notable optional arguments for this function.

Previous
Previous

The “ceiling” Function in R

Next
Next

The “floor” Function in R