Question: How do I randomize the elements of a stack?

I tried to define the following procedure, to shuffle, or randomize a stack 'S':

Mix:=proc(S)
SList:=convert(S,`list`):
subsop(1=NULL,SList):
SSList:=Shuffle(SList):
S:=convert(SSList,`table`):
end proc:

Unfortunately this procedure does not return a stack type, i.e. it transforms S to something different.
Anyway, I need a procedure (or maybe something more efficient), which randomizes a stack and replaces the old stack for the new
randomized one (i.e. S is randomized afterwards and still of type 'stack').

Can anyone help?

Thanks.

 

Please Wait...