chandra sekaran on Wed, 23 May 2018 06:46:14 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Fisher-Yates reverse shuffle is possible?


Fisher-Yates reverse shuffle is possible?

Following PARI-GP code. from www.rosettacode.org

FY(v)={
  forstep(n=#v,2,-1,
    my(i=random(n)+1,t=v[i]);
    v[i]=v[n];
    v[n]=t
  );
  v
};

(09:56) gp > FY(vector(10,i,i))
%14 = [2, 10, 7, 4, 5, 1, 9, 8, 3, 6]
(09:56) gp > FY(vector(10,i,i))
%15 = [2, 8, 1, 5, 9, 3, 7, 4, 6, 10]
(09:56) gp > FY(vector(10,i,i))
%16 = [8, 7, 2, 5, 4, 10, 6, 9, 3, 1]
(09:56) gp > FY(vector(10,i,i))
%17 = [10, 4, 2, 5, 7, 3, 6, 9, 1, 8]

Regards,
Chandrasekaran B