Shuffle Node
Overview
The Shuffle Node is used to randomize the order of elements in an array. It takes an array as input and outputs a new array with the elements in a shuffled order.
The Shuffle Node uses the Fisher-Yates (aka Knuth) shuffle algorithm to ensure a fair distribution of permutations.
- Inputs
- Outputs
- Editor Settings
Example 1: Shuffle an array of numbers
- Create an Array Node and set the values to
[1, 2, 3, 4, 5]
. - Create a Shuffle Node and connect the Array Node to its
Array
input. - Run the graph. The
Shuffled
output of the Shuffle Node should contain the numbers 1 through 5 in a random order.
Error Handling
The Shuffle Node will error if the Array
input is not provided or is not an array.
FAQ
Q: Can I shuffle an array of objects?
A: Yes, the Shuffle Node can shuffle arrays of any data type, including objects.
Q: Does the Shuffle Node modify the original array?
A: No, the Shuffle Node does not modify the original array. It creates a new array with the elements in a shuffled order.
Q: Is the shuffle algorithm truly random?
A: The Shuffle Node uses the Fisher-Yates (aka Knuth) shuffle algorithm, which is considered a fair shuffle algorithm. However, it relies on the JavaScript Math.random()
function, which is not suitable for cryptographic purposes.