trying to build a random choice engine

q)t:(w:abcd`e)

q)(t.w _ 3)[-3?-1+count t]
ae`c

q)t2:select w,other:(t.w _ i)[-3?-1+count t] from t
'length

My end goal:

q)select from t2
w o1 o2 o3

a b  c  e
b d  a  c
c a  d  b
d e  c  a
e c  d  b

q)flip wo1o2o3!(enlist t.w),flip {(t.w _ x)[-3?-1+count t]}each til count t

w o1 o2 o3


a b ?c ?e

b d ?e ?a

c d ?e ?b

d c ?a ?b

e d ?c ?b

q)select w,other:{(t.w _ x)[-3?-1+count t]}'[i] from t

w other


a b c d

b d c e

c e a b

d c b a

e a c b

q)select w,o1:other[;0],o2:other[;1],o3:other[;2] from select w,other:{(t.w _ x)[-3?-1+count t]}'[i] from t

w o1 o2 o3


a c ?b ?e

b e ?a ?c

c d ?e ?b

d b ?e ?a

e a ?c ?b

t,'exec flipo1o2`o3!flip -3?'w _/:i from t

This is great!  Would you mind walking me through it?

I understand that 

  table,'exec 

is a column join: https://code.kx.com/trac/wiki/QforMortals2/tables#Column-Join

But this one throws me for a loop

flip -3?'w _/:i from t

This makes sense: select -3?'w _/:i from t

but I don’t understand why it needs to be flipped again: select flip -3?'w _/:i from t

q)i:til 5

q)i
0 1 2 3 4

q)t.w _/:i
b c d e
a c d e
a b d e
a b c e
a b c d

q)-3?'t.w _/:i
b e d
c a e
d e a
b c e
b a c

q)flip -3?'t.w _/:i
c d b a b
d e d e a
e c e c d

q)o1o2`o3!flip -3?'t.w _/:i
o1| b d e a b
o2| d a a e a
o3| e c d c c

q)flipo1o2`o3!flip -3?'t.w _/:i
o1 o2 o3

b? c? d
d? c? e
e? a? b
c? b? a
a? c? b
q)