Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: choose with replacement



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     *
*************************************************



  • Prev by Date: How do u go about doing this---?
  • Next by Date: Re: Calc formula from table
  • Prev by thread: choose with replacement
  • Next by thread: RE: choose with replacement