If I have a list of 10K elements, and I want to randomly iterate through all of them, is there an algorithm that lets me access each element randomly, without just sorting them randomly first?
In other words, this would not be ideal:
const sorted = list .map(v => [math.random(), v]) .sort((a,b) => a[0]- b[0]); const sorted = list .map(v => [math.random(), v]) .sort((a,b) => a[0]- b[0]); It would be nice to avoid the sort call and the mapping call. My only idea would be to store everything in a hashmap and access the hash keys randomly somehow? Although that's just coming back to the same problem, afaict.