Skip to main content

Shuffle Node

Shuffle Node Screenshot

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

TitleData TypeDescriptionDefault ValueNotes
Arrayany[]The array to shuffle.(required)None

Example 1: Shuffle an array of numbers

  1. Create an Array Node and set the values to [1, 2, 3, 4, 5].
  2. Create a Shuffle Node and connect the Array Node to its Array input.
  3. Run the graph. The Shuffled output of the Shuffle Node should contain the numbers 1 through 5 in a random order.

Shuffle Node Example 1

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.

See Also