Knuth shuffle: Difference between revisions

(Add SETL)
 
(6 intermediate revisions by 4 users not shown)
Line 1,747:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
proc shuffle . a[] .
for i = len a[] downto 2
r = randomrandint i
swap a[r] a[i]
.
Line 1,891:
var max := self.Length;
for(int i := 0,; i < max,; i += 1)
{
var j := randomGenerator.nextInt(i,max);
Line 1,904:
public program()
{
var a := Array.allocate:(MAX).populate::(i => i );
console.printLine(a.randomize())
Line 4,527:
DUP SIZE 2 '''FOR''' j
j RAND * CEIL
DUP2 GET 3LAST PICKOVER j GET SWAP 4 ROLLD PUT j ROT PUT
-1 '''STEP'''
≫ '<span style="color:blue">KNUTH</span>' STO
Line 5,213:
after:
19 4 49 9 27 35 50 11 2 29 22 48 33 15 17 42 47 28 41 18 34 21 30 39 3 8 23 12 36 26 0 46 7 44 13 14 16 40 10 25 31 32 51 24 20 38 45 6 43 1 5 37</pre>
 
=={{header|Uiua}}==
{{works with|Uiua|0.10.0-dev.1}}
Build pairs of indexes to be swapped then apply these as a fold.
<syntaxhighlight lang="Uiua">
Knuth ← ∧(⍜⊏⇌)≡(⊟⌊×⚂.)⇌↘1⇡⧻.
Knuth ⇡10
</syntaxhighlight>
Typical output:
<pre>
[3 0 6 5 7 8 4 1 9 2]
</pre>
 
=={{header|UNIX Shell}}==
60

edits