Anonymous user
Knuth's algorithm S: Difference between revisions
→{{header|Julia}}
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output, used a simpler function for COMMAS, added a header separator.) |
|||
Line 890:
=={{header|Julia}}==
<lang julia>function makesofn(n::
buf = Vector{typeof(n)}(0)
i = 0
return function sofn(item)
i += 1
if i
push!(buf, item)
else
j = rand(1:i)
if j
end
return buf
end
end
nhist = zeros(Int, 10)
▲for i in 1:10^5
kas = makesofn(3)
for j in 0:8 kas(j) end
for k
end
println("Simulating sof3(0:9) 100000 times:")
for (i, c) in enumerate(nhist)
end</lang>
{{out}}
<pre>Simulating sof3(0:9) 100000 times:▼
0 → 29795
▲Simulating sof3(0:9) 100000 times:
=={{header|Kotlin}}==
|