Re: choose with replacement
- To: mathgroup@smc.vnet.net
- Subject: [mg10838] Re: [mg10800] choose with replacement
- From: Levasseur <levasseu@bit-net.com>
- Date: Tue, 10 Feb 1998 21:01:49 -0500
- References: <199802050558.AAA14419@smc.vnet.net.>
Daniel Sanders wrote: > > Hi, > > I'm new to Mathematica programming, and I'm a bit stumped to find the > code for the following maybe someone has a suggestion. > > Simply put, I want to make a new list from an existing finite list by > randomly choosing an element from list_1 to be included in list_2. > List_1 would loose that element, and the random number generator would > be reduced to correspond to the new length of the old list_1. This > process would continue untill list_1 has no elements, and list_2 has > all the elements of list_1 reordered. > > I have a feeling that this is not hard to do, but I can't seem to get it > right. Any suggestions? > > Dan Dan: This comes to mind. I think you could also use FixedPointList with SameTest checking for when the first list is empty. In[1]:= data=Range[1,10] Out[1]= {1,2,3,4,5,6,7,8,9,10} In[3]:= NestList[( a=First[#][[Random[Integer,{1,Length[First[#]]}]]];{ Complement[First[#],{a}],Union[Last[#],{a}]})&,{data,{}},Length[data]] Out[3]= {{{1,2,3,4,5,6,7,8,9,10},{}}, {{1,2,3,4,5,6,8,9,10},{7}}, {{1,2,3,4,5,8,9,10},{6,7}}, {{2,3,4,5,8,9,10},{1,6,7}}, {{3,4,5,8,9,10},{1,2,6,7}}, {{3,4,5,8,10},{1,2,6,7,9}}, {{3,4,5,8},{1,2,6,7,9,10}}, {{3,4,5},{1,2,6,7,8,9,10}}, {{3,4},{1,2,5,6,7,8,9,10}}, {{3},{1,2,4,5,6,7,8,9,10}}, {{},{1,2,3,4,5,6,7,8,9,10}}} Ken Levasseur ************************************************* Dr. Kenneth M. Levasseur * Chair, Mathematical Sciences * UMass Lowell, Lowell MA 01854 * Voice: (978) 934-2414 * Fax: (978)934-3053 * mailto:Kenneth_Levassseur@uml.edu * http://www.uml.edu/Dept/Math/LevasseuK.html * *************************************************
- References:
- choose with replacement
- From: Daniel Sanders <dman777@earthlink.net>
- choose with replacement