Knuth shuffle: Difference between revisions

m
→‎{{header|RPL}}: typos, minor code optimization
(→‎{{header|RPL}}: formatting)
m (→‎{{header|RPL}}: typos, minor code optimization)
Line 4,435:
 
=={{header|RPL}}==
The indexIndexes of RPL lists and arrays startsstart at 1.
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
Line 4,444:
DUP SIZE 2 '''FOR''' j
j RAND * FLOOR 1 +CEIL
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> ''( {listitems} ➝ {listitems} )'' <span style="color:grey">// works also with [arraysitems]</span>
for j from last downto 2 do:
let k = random integer in range 1 ≤ jkij
swap items[j] with items[k]
1,150

edits