Knuth shuffle: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: formatting) |
m (→{{header|RPL}}: typos, minor code optimization) |
||
Line 4,435: | Line 4,435: | ||
=={{header|RPL}}== |
=={{header|RPL}}== |
||
Indexes of RPL lists and arrays start at 1. |
|||
{{works with|Halcyon Calc|4.2.7}} |
{{works with|Halcyon Calc|4.2.7}} |
||
{| class="wikitable" |
{| class="wikitable" |
||
Line 4,444: | Line 4,444: | ||
≪ |
≪ |
||
DUP SIZE 2 '''FOR''' j |
DUP SIZE 2 '''FOR''' j |
||
j RAND * |
j RAND * CEIL |
||
DUP2 GET 3 PICK j GET SWAP 4 ROLLD PUT j ROT PUT |
DUP2 GET 3 PICK j GET SWAP 4 ROLLD PUT j ROT PUT |
||
-1 '''STEP''' |
-1 '''STEP''' |
||
≫ '<span style="color:blue">KNUTH</span>' STO |
≫ '<span style="color:blue">KNUTH</span>' STO |
||
| |
| |
||
<span style="color:blue">KNUTH</span> ''( { |
<span style="color:blue">KNUTH</span> ''( {items} ➝ {items} )'' <span style="color:grey">// works also with [items]</span> |
||
for j from last downto 2 do: |
for j from last downto 2 do: |
||
let k = random integer in range 1 ≤ |
let k = random integer in range 1 ≤ k ≤ j |
||
swap items[j] with items[k] |
swap items[j] with items[k] |
||