Function Repository Resource:

RandomSplit

Source Notebook

Randomly divide a list into a specified number of segments

Contributed by: Aster Ctor

ResourceFunction["RandomSplit"][list,n]

randomly cuts list into n segments.

ResourceFunction["RandomSplit"][n]

represents an operator form of ResourceFunction["RandomSplit"] that can be applied to an expression.

Examples

Basic Examples (2) 

Randomly cut a list of length 10 into five segments:

In[1]:=
ResourceFunction["RandomSplit"][Range@10, 5]
Out[1]=

Use another random cut:

In[2]:=
ResourceFunction["RandomSplit"][Range@10, 5]
Out[2]=

Scope (2) 

Use the operator form:

In[3]:=
split5 = ResourceFunction["RandomSplit"][5];
In[4]:=
split5[Range@10]
Out[4]=

The operator form is still random in each call:

In[5]:=
split5[Range@10]
Out[5]=

Possible Issues (1) 

If the number of segments exceeds the total length of the list, a message is issued:

In[6]:=
ResourceFunction["RandomSplit"][Range@10, 11]

Publisher

Aster Ctor (MoeNet)

Version History

  • 1.0.0 – 02 January 2020

Related Resources

License Information