Function Repository Resource:

# RandomPartition

Cut a list into random segments

Contributed by: Aster Ctor
 ResourceFunction["RandomPartition"][list,max] divides list into smaller pieces of length no more than max. ResourceFunction["RandomPartition"][list,min;;max] divides list into smaller pieces of length min to max. ResourceFunction["RandomPartition"][list,v] divides list into smaller pieces with lengths chosen from integer list v. ResourceFunction["RandomPartition"][list,p→v] divides list into smaller pieces with lengths chosen from list v according to weights p.

## Examples

### Basic Examples (1)

Divide a list of length 10 into smaller pieces of length no more than 4:

 In[1]:=
 Out[1]=

### Scope (3)

Divide a list of length 10 into small pieces of lengths 2 to 4:

 In[2]:=
 Out[2]=

Divide a list of length 10 into small pieces of length 2 or 4:

 In[3]:=
 Out[3]=

Divide a list of length 10 into small blocks of length 2 or 4 according to the specified weights:

 In[4]:=
 Out[4]=

### Possible Issues (1)

If the given set cannot be segmented as requested, the last elements will break the limit instead of being lost:

 In[5]:=
 Out[5]=

## Publisher

Aster Ctor (MoeNet)

## Version History

• 1.0.0 – 26 December 2019