Skip to content

randomSubsequence

Subhajit Sahu edited this page May 3, 2023 · 3 revisions

Pick an arbitrary subsequence.

Similar: randomSubsequence, subsequences, hasSubsequence, searchSubsequence.


function randomSubsequence(x, n, fr)
// x:  an array
// 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.randomSubsequence(x);
// → [ 1, 2 ]

xarray.randomSubsequence(x, 3);
// → [ 1, 3, 5 ]

xarray.randomSubsequence(x, 2);
// → [ 3, 5 ]


References

Clone this wiki locally