Skip to content

Instantly share code, notes, and snippets.

@lkatney
lkatney / Randomize a list.cls
Last active October 22, 2020 17:20
Randomize a list through apex
public static list<wrapper> randomize(list<wrapper> lst){
integer currentIndex = lst.size();
wrapper temporaryValue;
integer randomIndex;
// While there remain elements to shuffle...
while (0 != currentIndex) {
// Pick a remaining element...
randomIndex = integer.valueOf(Math.floor(Math.random() * currentIndex));
currentIndex -= 1;
// And swap it with the current element.