Generating Random Values
The random function generates values that you can influence by adding a number, list, or distribution.
Enter random\(( )\) to generate a single value sampled uniformly from the interval \([0,1)\).
Add a number within the parentheses, like random\((2)\), displays that amount of random values.
To randomly sample from a list of numbers, enter list.random\(( )\).
For example, if you enter \(\mathbf{[1,2,3]}\).random\(\mathbf{( )}\) the calculator will return a single value sampled uniformly from the list.
Rerandomizing and Random Seeds
If any expression contains a random function, a Randomize icon will appear in the header of the expression list or Notebook toolbar.
Behind the scenes, Desmos uses a pseudorandom number generator (PRNG) to create sequences of numbers that look random, even though they’re generated by a fixed process. The sequence is based on an initial value called a seed. Clicking Randomize sto set the global seed to a new value and rerandomize all expressions that use a random function.
If you’d like more control over a specific random function, you can enter a seed value, such as random\(\mathbf{(2,a)}\). Changing the value of \(a\) will only rerandomize that one expression, rather than the entire expression list or notebook. This can be especially useful with sliders, since moving a slider can trigger new random values automatically, such as in an animation or simulation.
While adding a seed value can influence how randomness behaves, it doesn’t guarantee the same value each time.
Change to Random Seeds in Function Definitions
Starting in March 2024, when the random or shuffle function appears inside a function definition, the seed automatically includes the values of that function’s parameters. As a result, each time the function is applied to different inputs, it will generate different random values.
For example, \(f(x)=\) random\(( )\) previously produced the same value for every input, meaning \(f(1)\) and \(f(2)\) would always match. With the new behavior, \(f(1)\) and \(f(2)\) now produce different results, while repeated calls of \(f(1)\) still match.
This change makes randomness behave more intuitively. Different inputs lead to different random values, and identical inputs stay consistent and open the door to fun applications such as the Random Walk graph.
Graphs created before March 2024 still exhibit the previous behavior by default, but they will offer the option to update to the new behavior.