Tuesday, June 16, 2026
HomeLanguagesJavascriptD3.js shuffler() Method

D3.js shuffler() Method

With the help of d3.shuffler() method, we can get the random function of shuffle which can be used to shuffle the random values of an array by using this method.

Syntax:

d3.shuffler( random )

Return value: It returns the random shuffle function.

Note: To execute the below examples you have to install the d3 library by using this command prompt we have to execute the following command.

npm install d3

Example 1: In this example, we can see that by using d3.shuffler() method, we are able to get the random shuffle function which we can use it to shuffle the elements in an array by using this method.

Javascript




// Defining d3 contrib variable  
var d3 = require('d3');
  
const random = d3.randomLcg(0.67019185816);
var gfg = d3.shuffler(random);
  
console.log(gfg([0, 1, 2, 3, 4]));


Output:

[ 3, 0, 4, 2, 1 ]

Example 2:

Javascript




// Defining d3 contrib variable  
var d3 = require('d3');
  
const random = d3.randomLcg(0.5816);
var gfg = d3.shuffler(random);
  
console.log(gfg([5, 6, -1, 3, 4]));


Output:

[3, 5, 6, -1, 4]

Example 3:

Javascript




// Defining d3 contrib variable  
var d3 = require('d3');
  
for(var i = 0.1; i <= 0.5; i+=0.1) {
    var random = d3.randomLcg(i);
    var gfg = d3.shuffler(random);
      
    console.log(gfg([-5, 6, -1, 3, -4]));
}


Output:

[ -4, 6, -5, -1, 3 ]
[ -1, 3, -5, -4, 6 ]
[ -5, -4, 6, -1, 3 ]
[ -1, 3, -4, -5, 6 ]
[ 6, -1, -5, -4, 3 ]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS