%mathpiper,def="Sample"

//Retract("Sample",*);

Sample(list, sampleSize) :=
[
    Check(IsList(list), "Argument", "The first argument must be a list.");
    
    Check(IsInteger(sampleSize) And sampleSize > 0, "Argument", "The second argument must be an integer which is greater than 0.");
    
    list := Shuffle(list);

    Take(list, sampleSize);
];

%/mathpiper





%mathpiper_docs,name="Sample",categories="User Functions;Statistics & Probability",access="experimental"
*CMD Sample --- takes a random sample of elements from a list
*STD
*CALL
	Sample(list,sampleSize)

*PARMS
{list} -- a list of elements
{sampleSize} -- the size of the sample to take from the list

*DESC
This function takes a random sample of items from a list and returns
a list which contains the sample.

*E.G.
In> Sample({a,b,c,d,e,f,g},3)
Result: {a,c,g}

%/mathpiper_docs



