function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ChowChow 

Random numbers without repetition

Hi

 

Can anyone suggest a pseudo code, to get the random number without repetition?

 

I have 80 numbers, where i need to pick 20 random numbers out of those 80 and display them on VF page.

But there should be no repetition in the picked 20 random numbers.

 

 

Thanks.

Ritesh AswaneyRitesh Aswaney

Hey

Just curious on what came out my suggestion the other day - were you able to pick out a random 20 ?

ChowChow

Hi Ritesh,

 

Thank You, i am able to pick random 20 out of 80...

 

But need without repetition.

sfdcfoxsfdcfox

 

Set<Integer> randomNumbers = new Set<Integer>();
while(randomNumbers.size()<20) {
  Decimal randomNumber = (Math.random()*80)+1;
  randomNumbers.add(randomNumber.intValue());
}

Enjoy!