Click here to Skip to main content
15,903,856 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Win Forms Drag n Drop email to .EML file Pin
Bernhard Hiller11-Mar-14 0:08
Bernhard Hiller11-Mar-14 0:08 
GeneralRe: C# Win Forms Drag n Drop email to .EML file Pin
Member 875270111-Mar-14 0:13
Member 875270111-Mar-14 0:13 
GeneralRe: C# Win Forms Drag n Drop email to .EML file Pin
Bernhard Hiller11-Mar-14 0:31
Bernhard Hiller11-Mar-14 0:31 
GeneralRe: C# Win Forms Drag n Drop email to .EML file Pin
Member 875270111-Mar-14 0:34
Member 875270111-Mar-14 0:34 
QuestionC# Windos app with SQl Issue Pin
manumaxma10-Mar-14 22:32
manumaxma10-Mar-14 22:32 
AnswerRe: C# Windos app with SQl Issue Pin
Eddy Vluggen11-Mar-14 0:59
professionalEddy Vluggen11-Mar-14 0:59 
QuestionDatagridview Timed Output Pin
Su069110-Mar-14 18:25
Su069110-Mar-14 18:25 
AnswerRe: Datagridview Timed Output Pin
OriginalGriff10-Mar-14 22:41
mveOriginalGriff10-Mar-14 22:41 
AnswerRe: Datagridview Timed Output Pin
Richard MacCutchan10-Mar-14 22:46
mveRichard MacCutchan10-Mar-14 22:46 
QuestionShortest Way to Shuffle Array Pin
computerpublic10-Mar-14 16:23
computerpublic10-Mar-14 16:23 
AnswerRe: Shortest Way to Shuffle Array Pin
BillWoodruff10-Mar-14 22:35
professionalBillWoodruff10-Mar-14 22:35 
GeneralRe: Shortest Way to Shuffle Array Pin
Simon_Whale11-Mar-14 0:00
Simon_Whale11-Mar-14 0:00 
GeneralRe: Shortest Way to Shuffle Array Pin
computerpublic11-Mar-14 6:59
computerpublic11-Mar-14 6:59 
GeneralRe: Shortest Way to Shuffle Array Pin
Simon_Whale11-Mar-14 7:13
Simon_Whale11-Mar-14 7:13 
GeneralRe: Shortest Way to Shuffle Array Pin
computerpublic11-Mar-14 7:20
computerpublic11-Mar-14 7:20 
GeneralRe: Shortest Way to Shuffle Array Pin
Simon_Whale11-Mar-14 7:29
Simon_Whale11-Mar-14 7:29 
GeneralRe: Shortest Way to Shuffle Array Pin
computerpublic11-Mar-14 6:57
computerpublic11-Mar-14 6:57 
GeneralRe: Shortest Way to Shuffle Array Pin
BobJanova12-Mar-14 3:01
BobJanova12-Mar-14 3:01 
AnswerRe: Shortest Way to Shuffle Array Pin
GuyThiebaut10-Mar-14 22:47
professionalGuyThiebaut10-Mar-14 22:47 
GeneralRe: Shortest Way to Shuffle Array Pin
BillWoodruff10-Mar-14 23:22
professionalBillWoodruff10-Mar-14 23:22 
GeneralRe: Shortest Way to Shuffle Array Pin
computerpublic11-Mar-14 7:03
computerpublic11-Mar-14 7:03 
AnswerRe: Shortest Way to Shuffle Array Pin
Pete O'Hanlon11-Mar-14 7:51
mvePete O'Hanlon11-Mar-14 7:51 
AnswerRe: Shortest Way to Shuffle Array Pin
Henrik Jonsson13-Mar-14 11:10
Henrik Jonsson13-Mar-14 11:10 
This generic function provides a quick way of randomly shuffling (reordering) the items in-place in an existing array:

public static void ShuffleArray<T>(T[] array)
{
    Random rnd = new Random();
    int[] order = new int[array.Length];
    for (int i = 0; i < array.Length; i++)
    {
       order[i] = rnd.Next();
    }
    Array.Sort(order, array);
} 

It can we rewritten as
Random rnd = new Random();
Array.Sort(array.Select(r => rnd.Next()).ToArray(), array);

giving just slightly worse performance.


According to my tests the use of Array.Sort is about three times faster than the OrderBy solution for a million integer array.
AnswerRe: Shortest Way to Shuffle Array Pin
Henrik Jonsson13-Mar-14 22:05
Henrik Jonsson13-Mar-14 22:05 
QuestionRMO programming Pin
Member 1064095910-Mar-14 10:22
Member 1064095910-Mar-14 10:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.