using Plots
function NaiveShuffle(x)
r=copy(x)
l=length(r)
for i in 1:l
j=rand(1:l)
r[[i,j]]=r[[j,i]]
end
r
end
function FisherShuffle(x)
r=copy(x)
l=length(r)
for i in 1:l
j=rand(i:l)
r[[i,j]]=r[[j,i]]
end
r
end
function SampleShuffle(n,tr=1000000)
RN=Dict()
RF=Dict()
for _ in 1:tr
r=collect(1:n)
s0=NaiveShuffle(r)
s1=FisherShuffle(r)
(s0∈keys(RN)) ? (RN[s0]+=1) : RN[s0]=1
(s1∈keys(RF)) ? (RF[s1]+=1) : RF[s1]=1
end
Dict([ k=>[RN[k] RF[k]]./tr for k in keys(RN)∩keys(RF) ])
end
function plotShuffle(n,tr=1000000)
R=SampleShuffle(n,tr)
vals=reduce(vcat,values(R))
scatter(vals,label=["Naive" "Fisher"],xrotation=30,xticks=(1:1:length(vals),collect(keys(R))))
end
X=plotShuffle(4)