Re: Quick Question

*To*: mathgroup at smc.vnet.net*Subject*: [mg78146] Re: [mg78090] Quick Question*From*: János <janos.lobb at yale.edu>*Date*: Sat, 23 Jun 2007 07:25:07 -0400 (EDT)*References*: <200706221050.GAA16639@smc.vnet.net>

On Jun 22, 2007, at 6:50 AM, rob cronin wrote: > Quick Question: > > With Mathematica 5.2 is there any way to scramble a simple list of > numbers: > i.e. randomly rearange the list {1,2,3,4,5,6} without any apparent > order. > > Kind regards > Here is a newbie approach: In[1]:= lst = {1, 2, 3, 4, 5, 6} From the Help of Union you can take UnsortedUnion In[4]:= UnsortedUnion[x_] := Module[{f}, f[y_] := (f[y] = Sequence[ ]; y); f /@ x] Then one scramble might look like : In[7]:= rst = UnsortedUnion[ Table[lst[[Random[Integer, {1, Length[lst]}]]], {i, 1, Length[lst]* Length[lst]}]] Out[7]= {4, 6, 2, 3, 5, 1} If course it is good only if the elements of the starting lst are distinct. J=E1nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice)

**References**:**Quick Question***From:*"rob cronin" <cronin_rob@hotmail.com>