- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5
 
randomPermutation$
        Subhajit Sahu edited this page May 3, 2023 
        ·
        3 revisions
      
    Pick an arbitrary permutation!
Alternatives: randomPermutation, randomPermutation$.
Similar: randomPermutation, permutations, hasPermutation.
function randomPermutation$(x, n, fr)
// x:  an array (updated!)
// n:  number of values [-1 ⇒ any]
// fr: random number generator ([0, 1))const xarray = require('extra-array');
var x = [1, 2, 3, 4, 5];
xarray.randomPermutation$(x, 5);
// → [ 2, 4, 5, 1, 3 ]
x;
// → [ 2, 4, 5, 1, 3 ]
var x = [1, 2, 3, 4, 5];
xarray.randomPermutation$(x, 5);
// → [ 5, 3, 1, 2, 4 ]
var x = [1, 2, 3, 4, 5];
xarray.randomPermutation$(x, 3);
// → [ 5, 3, 1 ]