+ Start a Discussion
:) :) :) :) :):) :) :) :) :) 

Shuffle or Randomize a List

How can I shuffle a List Collection in APEX.


Ex: List<Account> acc = new List<Account>({Acc1, Acc2, Acc3,....,AccN});


acc.shuffle(); or acc.random(); // I want something that shuffle or randomize the primitive or sobject data inside the list.


output should be ==> {Acc2048, Acc179, Acc8632,.....,AccN} 


Thanks in advance. 





There is no random/shuffle method in apex but we can make use of random methid of maths class and can get a random number like in the below link: