The need is the possible desire for reproducible results, which may for example come from trying to debug your program, or of course from trying to redo what it does:

These two results we will “never” reproduce as I just asked for something “random”:

R> sample(LETTERS, 5) [1] "K" "N" "R" "Z" "G" R> sample(LETTERS, 5) [1] "L" "P" "J" "E" "D"

These two, however, are identical *because I set the seed*:

R> set.seed(42); sample(LETTERS, 5) [1] "X" "Z" "G" "T" "O" R> set.seed(42); sample(LETTERS, 5) [1] "X" "Z" "G" "T" "O" R>

There is vast literature on all that; Wikipedia is a good start. In essence, these RNGs are called Pseudo Random Number Generators because they are in fact *fully algorithmic*: given the same seed, you get the same sequence. And that *is a feature* and not a bug.

### Related Posts:

- Sample random rows in dataframe
- How do I select the first row in an R data frame that meets certain criteria?
- Poker hand range chart visualization in R
- Critical t values in R
- Error in
: object of type ‘closure’ is not subsettable - What does %>% function mean in R?
- How to join (merge) data frames (inner, outer, left, right)
- How to generate a random number in C++?
- rbind error: “names do not match previous names”
- rbind error: “names do not match previous names”
- R Error in x$ed : $ operator is invalid for atomic vectors
- What does na.rm=TRUE actually means?
- Remove legend ggplot 2.2
- How do I replace NA values with zeros in an R dataframe?
- R on MacOS Error: vector memory exhausted (limit reached?)
- Why use as.factor() instead of just factor()
- mean() warning: argument is not numeric or logical: returning NA
- Why do I get “number of items to replace is not a multiple of replacement length”
- Drop data frame columns by name
- How to generate a random int in C?
- How can two strings be concatenated?
- Remove a row from a data table in R
- “Error: Continuous value supplied to discrete scale” in default data set example mtcars and ggplot2
- Why am I getting “algorithm did not converge” and “fitted prob numerically 0 or 1” warnings with glm?
- How does one reorder columns in a data frame?
- Arcsine transformation of percentage data
- R loop that adds following numbers to each element in list
- Can I calculate z-score with R?
- Using Caret Package but Getting Error in library(e1071)
- Function to clear the console in R and RStudio
- Generating random whole numbers in JavaScript in a specific range?
- Why I get this error writing data to a file
- Remove NA values from a vector
- character string is not in a standard unambiguous format
- Remove rows with all or some NAs (missing values) in data.frame
- duplicate ‘row.names’ are not allowed error
- How to count the number of observations in R like Stata command count
- srand(time(0)) and random number generation
- Generate random string/characters in JavaScript
- Error: unexpected ‘}’ in “}” in R [duplicate]
- Error : length of ‘dimnames’ [2] not equal to array extent
- Mean of a column in a data frame, given the column’s name
- Best way to generate a random float in C#
- Generate random sentences in python
- What is the difference between rm() and rm(list=ls())?
- Random number c++ in some range
- Understanding `scale` in R
- What is the significance of the number, 32767?
- Error with apply function
- file.path function in R
- Reshaping data.frame from wide to long format
- Remove rows with all or some NAs (missing values) in data.frame
- Converting data frame column from character to numeric
- How to set limits for axes in ggplot2 R plots?
- Rotating and spacing axis labels in ggplot2
- duplicate ‘row.names’ are not allowed error
- How to sum data.frame column values?
- Error: invalid subscript type ‘list’ in R
- Is there a dictionary functionality in R
- “non-numeric argument to binary operator” error in R
- Java Generate Random Number Between Two Given Values
- Random shuffling of an array
- ggplot2 manually specifying colour with geom_line
- How to update a package in R?
- Error: Invalid input: date_trans works with objects of class Date only
- Matrix expression causes error “requires numeric/complex matrix/vector arguments”?
- NAs are not allowed in subscripted assignments
- Non-conformable arrays error in code
- Unused arguments in R
- How to convert a data frame column to numeric type?
- Boxplot dplyr: Error: non-numeric argument to binary operator
- Error: ggplot2 doesn’t know how to deal with data of class matrix?
- What is integer overflow in R and how can it happen?
- Creating box plot on exercise
- changing title in multiplot ggplot2 using grid.arrange
- How to split data into training/testing sets using sample function
- Get a random item from a JavaScript array
- How to sort a data frame by alphabetic order of a character variable in R?
- Get a random sample with replacement
- Error in na.fail.default(as.ts(x)) : missing values in object in time series forecasting
- Error in contrib.url(repos, “source”) in R trying to use CRAN without setting a mirror Calls: install.packages -> contrib.url Execution halted
- Geometric Mean: is there a built-in?
- Error in xj[i] : invalid subscript type ‘list’
- Error in eval(predvars, data, env) : invalid ‘envir’ argument of type ‘character’
- Creating random numbers with no duplicates
- IF “OR” multiple conditions
- Seeding the random number generator in Javascript
- Convert the values in a column into row names in an existing data frame
- Problems Generating A Math.random Number, Either 0 or 1
- Merge data frames based on rownames in R
- The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe
- Simple way to create matrix of random numbers
- How to use random in BATCH script?
- Generating a Random Number for HTML
- Getting a random value from a JavaScript array
- C++ Simple Dice roll – how to return multiple different random numbers [duplicate]
- Subset and ggplot2
- How do I print a hexadecimal number with leading 0 to have width 2 using sprintf?
- Shuffle an array with python, randomize array item order with python
- How to deal with “data of class uneval” error from ggplot2?