Skip to main content
added 8 characters in body
Source Link
Caspar Harmer
  • 20.6k
  • 4
  • 35
  • 69

I figured it out. Thanks for the response. I used a nested for loop, and a random generator, to randomly grab elements from List1, sequentially assign them to List2, and then print List2 using VisualForce.

public sortController() { sortparts=[SELECT ABC_Code__c, Name FROM sm1e_smPart__c WHERE ABC_Code__c = 'C'];
count = (integer)aggResult[0].get('expr0'); //Convert number of Cs to integer randomized = new List<sm1e_smPart__c>(count); for(Integer i = 0; i < count; i++) { for(Integer j = 0; j < count; j++) { Integer rand = Math.round(Math.random()*1000); while(rand > count-1){rand = Math.round(Math.random()*1000);} randomized[j] = sortparts[rand]; } } }

public sortController()
{
    sortparts=[SELECT ABC_Code__c, Name FROM sm1e_smPart__c WHERE ABC_Code__c = 'C'];  
    count = (integer)aggResult[0].get('expr0'); //Convert number of Cs to integer
    randomized = new List<sm1e_smPart__c>(count);
    for(Integer i = 0; i < count; i++)
    {
        for(Integer j = 0; j < count; j++)
        {
            Integer rand = Math.round(Math.random()*1000);
            while(rand > count-1){rand = Math.round(Math.random()*1000);}
            randomized[j] = sortparts[rand];
        }
    }
}

I figured it out. Thanks for the response. I used a nested for loop, and a random generator, to randomly grab elements from List1, sequentially assign them to List2, and then print List2 using VisualForce.

public sortController() { sortparts=[SELECT ABC_Code__c, Name FROM sm1e_smPart__c WHERE ABC_Code__c = 'C'];
count = (integer)aggResult[0].get('expr0'); //Convert number of Cs to integer randomized = new List<sm1e_smPart__c>(count); for(Integer i = 0; i < count; i++) { for(Integer j = 0; j < count; j++) { Integer rand = Math.round(Math.random()*1000); while(rand > count-1){rand = Math.round(Math.random()*1000);} randomized[j] = sortparts[rand]; } } }

I figured it out. Thanks for the response. I used a nested for loop, and a random generator, to randomly grab elements from List1, sequentially assign them to List2, and then print List2 using VisualForce.

public sortController()
{
    sortparts=[SELECT ABC_Code__c, Name FROM sm1e_smPart__c WHERE ABC_Code__c = 'C'];  
    count = (integer)aggResult[0].get('expr0'); //Convert number of Cs to integer
    randomized = new List<sm1e_smPart__c>(count);
    for(Integer i = 0; i < count; i++)
    {
        for(Integer j = 0; j < count; j++)
        {
            Integer rand = Math.round(Math.random()*1000);
            while(rand > count-1){rand = Math.round(Math.random()*1000);}
            randomized[j] = sortparts[rand];
        }
    }
}
Source Link

I figured it out. Thanks for the response. I used a nested for loop, and a random generator, to randomly grab elements from List1, sequentially assign them to List2, and then print List2 using VisualForce.

public sortController() { sortparts=[SELECT ABC_Code__c, Name FROM sm1e_smPart__c WHERE ABC_Code__c = 'C'];
count = (integer)aggResult[0].get('expr0'); //Convert number of Cs to integer randomized = new List<sm1e_smPart__c>(count); for(Integer i = 0; i < count; i++) { for(Integer j = 0; j < count; j++) { Integer rand = Math.round(Math.random()*1000); while(rand > count-1){rand = Math.round(Math.random()*1000);} randomized[j] = sortparts[rand]; } } }