Click here to Skip to main content
15,923,273 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
Richard Deeming24-Oct-17 4:05
mveRichard Deeming24-Oct-17 4:05 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot24-Oct-17 4:10
harold aptroot24-Oct-17 4:10 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
megaadam24-Oct-17 4:20
professionalmegaadam24-Oct-17 4:20 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff24-Oct-17 4:20
professionalBillWoodruff24-Oct-17 4:20 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot24-Oct-17 5:10
harold aptroot24-Oct-17 5:10 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff24-Oct-17 22:03
professionalBillWoodruff24-Oct-17 22:03 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot25-Oct-17 1:10
harold aptroot25-Oct-17 1:10 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff25-Oct-17 2:44
professionalBillWoodruff25-Oct-17 2:44 
I think you mean:
while (--scount >= 0)
{
    ndx = rnd.Next(0, scount);

    yield return slist[ndx];

    // HA suggests: slist[scount - 1] into slist[ndx] (optionally set slist[scount - 1] to default(T)).

    slist[ndx] = slist[scount];
}
Using 'scount - 1 would throw an error at the last iteration. I can't make sense of the suggestion re using 'default T. I don't go deep enough down the stack to evaluate the expense of a call to'RemoveAt vs. a shift of a value to another slot.

By the way, this discussion is a perfect example of content on the Lounge that, imho, should be happening on (or preserved on) another Forum. But, I have beaten the drum over this issue so often that I'm not going there Smile | :)

thanks. Bill
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)

GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot25-Oct-17 5:21
harold aptroot25-Oct-17 5:21 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff25-Oct-17 6:56
professionalBillWoodruff25-Oct-17 6:56 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot25-Oct-17 7:08
harold aptroot25-Oct-17 7:08 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
Dan Neely25-Oct-17 3:38
Dan Neely25-Oct-17 3:38 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff25-Oct-17 3:44
professionalBillWoodruff25-Oct-17 3:44 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
Dan Neely25-Oct-17 5:05
Dan Neely25-Oct-17 5:05 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
BillWoodruff25-Oct-17 6:41
professionalBillWoodruff25-Oct-17 6:41 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
Dan Neely25-Oct-17 7:37
Dan Neely25-Oct-17 7:37 
GeneralRe: On list.OrderBy(x => random.Next()) Pin
harold aptroot25-Oct-17 5:09
harold aptroot25-Oct-17 5:09 
GeneralCopy-Paste Coding Culture Pin
Jacquers24-Oct-17 2:07
Jacquers24-Oct-17 2:07 
AnswerRe: Copy-Paste Coding Culture Pin
W Balboos, GHB24-Oct-17 2:11
W Balboos, GHB24-Oct-17 2:11 
GeneralCopy-Paste Everything! Pin
megaadam24-Oct-17 2:54
professionalmegaadam24-Oct-17 2:54 
GeneralRe: Copy-Paste Coding Culture Pin
Marc Clifton24-Oct-17 3:01
mvaMarc Clifton24-Oct-17 3:01 
GeneralRe: Copy-Paste Coding Culture Pin
Dan Neely24-Oct-17 3:02
Dan Neely24-Oct-17 3:02 
GeneralRe: Copy-Paste Coding Culture Pin
Jacquers24-Oct-17 3:51
Jacquers24-Oct-17 3:51 
GeneralRe: Copy-Paste Coding Culture Pin
PeejayAdams24-Oct-17 3:13
PeejayAdams24-Oct-17 3:13 
GeneralRe: Copy-Paste Coding Culture Pin
F-ES Sitecore24-Oct-17 3:17
professionalF-ES Sitecore24-Oct-17 3:17 

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.