<?xml version="1.0" encoding="windows-1252"?>
<node id="1007725" title="Re: Idiom to return 0 or random number of array elements" created="2012-12-07 07:08:35" updated="2012-12-07 07:08:35">
<type id="11">
note</type>
<author id="190859">
bart</author>
<data>
<field name="doctext">
&lt;c&gt;
my @subset = @array[0 .. int rand(1 + @array)-1];
&lt;/c&gt;
If the second parameter for the &lt;c&gt;..&lt;/c&gt; operator is lower than the first parameter, then you'll get no items.

&lt;p&gt;BTW this will &lt;em&gt;not&lt;/em&gt; return a random number of random elements. Instead it'll return the first N elements where N is a random number. If you want random elements, you could shuffle the array first.</field>
<field name="root_node">
1007684</field>
<field name="parent_node">
1007684</field>
</data>
</node>
