Function Repository Resource:

RandomSampleOf

Source Notebook

Randomly select a given number of elements from a list or expression

Contributed by: Arnoud Buzing

ResourceFunction["RandomSampleOf"][n]

randomly selects n elements from the list or expression it is applied to.

Details

ResourceFunction["RandomSampleOf"] is effectively an operator version of RandomSample, but provides a clearer and more concise syntax.

Examples

Basic Examples (1) 

Randomly select five elements from a word list:

In[1]:=
WordList[] // ResourceFunction["RandomSampleOf"][5]
Out[1]=

Properties and Relations (2) 

Randomly select ten element from a list of integers:

In[2]:=
Range[400] // ResourceFunction["RandomSampleOf"][10]
Out[2]=

RandomSampleOf is effectively an operator version of RandomSample, but with a more concise syntax:

In[3]:=
Range[400] // RandomSample[#, 10] &
Out[3]=

Publisher

Arnoud Buzing

Requirements

Wolfram Language 12.3 (May 2021) or above

Version History

  • 1.0.0 – 29 November 2023

Related Resources

License Information