I have seen people[1] suggesting the use of
function choose(arr, n){
if(n > arr.length) throw "Invalid";
return arr.sort(() => 0.5 - Math.random()).slice(0, n);
}
to randomly choose n elements from a list. However, depending on the sorting algorithm implementation, it might not terminate due to how the compare function is not consistent over time.
My question would be does the specification guarantee termination, i.e. efficiency aside, is the above function safe to use. §22.1.3.25 doesn't seem to give any information on it[2].