<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Randomly choose an element in a list and remove the chosen one for next round in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/462040#M70685</link>
    <description>&lt;P&gt;One edited version of&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt;&amp;nbsp;version, which uses the Remove From return value (it returns the value of removed elements as list). This code might not be as easy to read, but sometimes using the return value from Remove From is useful:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

theList = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

While(N Items(theList) &amp;gt; 1,
	// returns list of removed elements, we remove one value, so get first index
	r_val = Remove From(theList, Random Integer(N Items(theList)))[1]; 
	Print(Eval Insert("The chosen item was ^r_val^."));
);

Print("The chosen item is " || theList[1] || ".");&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Feb 2022 06:15:12 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-02-18T06:15:12Z</dc:date>
    <item>
      <title>Randomly choose an element in a list and remove the chosen one for next round</title>
      <link>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461681#M70660</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a list[1,2,3,4,5,6,7,8,9,10] that I want to randomly choose an element, and then remove that element from the list for the next random selection. I need to repeat the selections 4 times.&lt;/P&gt;&lt;P&gt;Is there a easy way to remove the selected element in the list? Both Remove and Remove From need the ith index of the elements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:10:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461681#M70660</guid>
      <dc:creator>midori555</dc:creator>
      <dc:date>2023-06-09T18:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly choose an element in a list and remove the chosen one for next round</title>
      <link>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461928#M70678</link>
      <description>&lt;P&gt;Would something like this work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;theList = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

while(nitems(theList) &amp;gt; 1, 
r=random integer(nitems(theList));

print("The chosen item was " || theList[r] || ". Element number " || char(r) || ".");

remove from(theList, r);
);

print("The chosen item is " || theList[1] || ".");
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 19:54:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461928#M70678</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2022-02-17T19:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly choose an element in a list and remove the chosen one for next round</title>
      <link>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461931#M70681</link>
      <description>&lt;P&gt;You could also use Random Shuffle to randomize the list (matrix) and then loop over the randomized list (matrix) four times or pick first four elements&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

m = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
m_rand = Random Shuffle(m);
Show(m, m_rand);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 20:34:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/461931#M70681</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-02-17T20:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Randomly choose an element in a list and remove the chosen one for next round</title>
      <link>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/462040#M70685</link>
      <description>&lt;P&gt;One edited version of&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt;&amp;nbsp;version, which uses the Remove From return value (it returns the value of removed elements as list). This code might not be as easy to read, but sometimes using the return value from Remove From is useful:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

theList = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};

While(N Items(theList) &amp;gt; 1,
	// returns list of removed elements, we remove one value, so get first index
	r_val = Remove From(theList, Random Integer(N Items(theList)))[1]; 
	Print(Eval Insert("The chosen item was ^r_val^."));
);

Print("The chosen item is " || theList[1] || ".");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Feb 2022 06:15:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Randomly-choose-an-element-in-a-list-and-remove-the-chosen-one/m-p/462040#M70685</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-02-18T06:15:12Z</dc:date>
    </item>
  </channel>
</rss>

