p5.js | shuffle() function
The shuffle() function in p5.js is used to shuffle the order of given array elements.
Syntax:
shuffle(Array)
Parameters: This function accepts a parameter Array whose elements are to be shuffled.
Return Value: It returns the shuffled array.
Below program illustrates the shuffle() function in p5.js:
Example-1:
function setup() { // Creating Canvas size createCanvas(500, 90); // Set the background color background(220); // Initializing the arrays let Array1 = ['IT', 'CSE', 'ECE']; // Calling to shuffle() function. let Array2 = shuffle(Array1); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new shuffled array text("Shuffled array is : " + Array2, 50, 30); } |
Output:

Example-2:
function setup() { // Creating Canvas size createCanvas(500, 90); // Set the background color background(220); // Calling to shuffle() function on an array // Taken as the parameter let Array = shuffle(['Ram', 'Shayam', 'Geeta', 'Anita']); // Set the size of text textSize(16); // Set the text color fill(color('red')); // Getting new shuffled array text("Shuffled array is : " + Array, 50, 30); } |
Output:

NOTE: In the above codes, draw() function has not been used because if we use draw function then it does not give a clear output i.e, it keeps on changing the order of the array string continually and not giving any stagnant result.
Reference: https://p5js.org/reference/#/p5/shuffle
Recommended Posts:
- PHP | shuffle() Function
- D3.js | d3.shuffle() function
- Underscore.js | shuffle() with Examples
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | Ds\Map put() Function
- p5.js | nfc() function
- D3.js | d3.max() function
- p5.js | nfp() Function
- PHP | each() Function
- PHP | pi( ) Function
- CSS | rgb() Function
- D3.js | d3.min() function
- D3.js | d3.map.set() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



