Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>Input <code>InputArray</code>: Array of say integers</li> <li>Input <code>NumberCount</code>: Number of integers in InputArray</li> <li><p>Input <code>ShuffleRange</code>: Valid range a number is allowed to jump</p></li> <li><p><code>ShuffleWindowSize</code>: Processing window within which swapping happens. Its value is <code>ShuffleRange +1</code></p></li> <li><code>ShuffleIndexArray</code>: Indexes of input numbers in Shuffling Window, Invalid index will be <strong>INT_MIN</strong></li> </ul> <p>Initialise <code>ShuffleIndexArray</code></p> <blockquote> <pre><code>for (idx =0; idx &lt; ShuffleWindowSize; idx++) { ShuffleIndexArray[idx] = idx; } </code></pre> </blockquote> <p>Process <code>InputArray</code></p> <pre><code>for (idx = 0; idx &lt; NumberCount; idx++) { shuffleIdx = idx % ShuffleWindowSize; /* 1. Check if the Element has been moved from it's Original Position * 1.1 IF it was swapped already then move to next element * 1.2 ELSE perform shuffling within available window */ if (idx != ShuffleIndexArray[shuffleIdx]) { /* was swapped already */ goto LOOP_CONTINUE; } /* Get a random Index in the range [0, shuffleWinSize) */ randomSwapIdx = rand() % shuffleWinSize; /* OffSet */ /* Skip Invalid Indexes */ if (INT_MIN == shuffleIndexArray[randomSwapIdx]) { for (jdx = randomSwapIdx + shuffleWinSize - 1; jdx &gt; randomSwapIdx; jdx--) { if (INT_MIN != shuffleIndexArray[jdx % shuffleWinSize]) { randomSwapIdx = jdx % shuffleWinSize; break; } } } /* Get the actual index into InputArray */ randomSwapIdx = ShuffleIndexArray[randomSwapIdx]; /*Actual Index*/ /* Check if number gets to stay in original position */ if (idx == randomSwapIdx) { /* Lucky Bugger */ goto LOOP_CONTINUE; } /* Swapping of two numbers in InputArray */ swapInt = inputArr[idx]; inputArr[idx] = inputArr[randomSwapIdx]; inputArr[randomSwapIdx] = swapInt; /* Update indexes in Shuffle-Window Array */ ShuffleIndexArray[randomSwapIdx % ShuffleWindowSize] = idx; LOOP_CONTINUE: /* InputArray[idx] was processed. * Update ShuffleIndexArray */ ShuffleIndexArray[shuffleIdx] = ((idx + ShuffleWindowSize) &lt; NumberCount) ? (idx + ShuffleWindowSize) : INT_MIN; } </code></pre> <p>It's an in-place shuffling except we need another array of size <code>ShuffleWindowSize</code> to keep track of indexes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload