Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Cut a list into random segments
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. |
Divide a list of length 10 into smaller pieces of length no more than 4:
In[1]:= |
Out[1]= |
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]= |
If the given set cannot be segmented as requested, the last elements will break the limit instead of being lost:
In[5]:= |
Out[5]= |
This work is licensed under a Creative Commons Attribution 4.0 International License