Knuth shuffle: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: formatting) |
|||
Line 4,444: | Line 4,444: | ||
≪ |
≪ |
||
DUP SIZE 2 '''FOR''' j |
DUP SIZE 2 '''FOR''' j |
||
j RAND * FLOOR 1 + |
j RAND * FLOOR 1 + |
||
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''' |
|||
≫ |
≫ '<span style="color:blue">KNUTH</span>' STO |
||
| |
| |
||
<span style="color:blue">KNUTH</span> ''( {list} ➝ {list} )'' <span style="color:grey">// works also with [arrays]</span> |
|||
for j from last downto 2 do: |
for j from last downto 2 do: |
||
let k = random integer in range 1 ≤ j ≤ i |
let k = random integer in range 1 ≤ j ≤ i |