Let's say I have an array in Javascript:
var my_arr = [1,2,3,4,5,6];
There are numerous methods to shuffle it. Suppose I already have a function called shuffle
, like this:
shuffle(my_arr);
// The array could look something like [1,5,4,3,2,6];
However, with each run, the order changes. I am interested in finding out if it's possible to fix the shuffling to a specific value (a number, string, or anything else). The objective is to have the same result every time as long as the key remains unchanged. For example:
var my_arr = [1,2,3,4,5,6];
function shuffle_by_key(arr, key){....}
var new_arr1 = shuffle_by_key(my_arr, 1);
var new_arr2 = shuffle_by_key(my_arr, 2);
var new_arr3 = shuffle_by_key(my_arr, 1);
The new_arr1
output should match that of new_arr3
since they both share the same key "1".