Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'RandomChoice' topicStudent Support Forum > General > "RandomChoice"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
05/30/12 4:02pm

1. Create a list to choose from by appending the next larger element to your previous list.
2. Randomly select any element from that list.
3. Append that selection to your old list.
4. Optionally sort the result

OR all wrapped up into a single line:

In[1]:= f[v_]:=Sort[Join[v,{Join[v,{Last[v]+1}][[RandomInteger,Length[v]+1]]}]];
A={1,2,3,4,5,6};
A=f[A]

Out[3]= {1,2,3,3,4,5,6}

In[4]:= A=f[A]
Out[4]= {1,2,3,3,4,5,6,7}

In[5]:= A=f[A]
Out[5]= {1,2,3,3,4,5,6,6,7}

In[6]:= A=f[A]
Out[6]= {1,2,3,3,4,5,6,6,7,8}

Take that function apart piece by piece until you understand how it was constructed and how it works.

URL: ,

Subject (listing for 'RandomChoice')
Author Date Posted
RandomChoice endriuu 05/30/12 2:43pm
Re: RandomChoice Bill Simpson 05/30/12 4:02pm
Re: Re: RandomChoice endriuu 06/01/12 12:14pm
Re: Re: Re: RandomChoice Bill Simpson 06/01/12 8:03pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic