Asked By Aarthi Saravanakumar
12-Dec-05 01:57 PM
a level of Randomness..again by checking that if a number's destination index is the same as its source index..go in a loop and generate the next Random# that is not the same Index as the Source..
public static ListDTO[] Shuffle(ListDTO[] listDTO)
{
int newIndex;
ListDTO tempListDTO;
try
{
for (int i = 0; i < listDTO.Length; i++)
{
newIndex = new Random().Next(listDTO.Length);
while(i!=newIndex)
{
newIndex = new Random().Next(listDTO.Length);
}
tempListDTO = listDTO[i];
listDTO[i] = listDTO[newIndex];
listDTO[newIndex] = tempListDTO;
}
}
catch (Exception ex)
{
LoggerUtility.GetInstance().ApplicationLogger.Error("Error while shuffling ListDTO objects", ex);
}
return listDTO;
}