Welcome to the Monastery | |
PerlMonks |
RE: RE (tilly) 3: Fisher-Yates Shuffleby Adam (Vicar) |
on Aug 30, 2000 at 07:29 UTC ( [id://30257]=note: print w/replies, xml ) | Need Help?? |
First of all... don't worry about ranting. I took no offense, I'm just trying to understand this shuffle algorithm. Specifically I don't understand why the branch test is in there. Ok, on with the math! I almost failed numerical analysis and its been years since I've opened a calc book, so I'll trust you on your calculation of averages. Actually, your math makes sense up till the bit about trapezoids. <grin> However, I do NOT believe that I miss read the Fisher-Yates algorithm... its exactly as you said, I just re-conceptualized it. Either way you look at it, the size of the range for rand is decremented one each time. This means that the range for the first pass at an array of size N is the same as the size of the range for the second pass of an array of size N+1. I think we're on the same page, I'm just off on the fringes. Which is ok. What this all boils down to is that the branch is not needed. Oh,
In Section
Meditations
|
|