Function Repository Resource:

RandomBins

Source Notebook

Distribute a list into random bins

Contributed by: Ed Pegg Jr

ResourceFunction["RandomBins"][list,n]

randomly distributes the elements of list into n bins.

Examples

Basic Examples (1) 

Randomly put the numbers 1 to 10 into three bins:

In[1]:=
ResourceFunction["RandomBins"][Range[10], 3]
Out[1]=

Scope (1) 

Place a set of Tuples into four bins:

In[2]:=
ResourceFunction["RandomBins"][Tuples[Range[5], {2}], 4]
Out[2]=

Possible Issues (1) 

Since the process is random, there may be fewer bins returned than the number of bins requested:

In[3]:=
ResourceFunction["RandomBins"][Range[4], 5]
Out[3]=

Neat Examples (1) 

Randomly split the K9 complete graph into three graphs:

In[4]:=
Graph[UndirectedEdge @@@ #, VertexLabels -> "Name"] & /@ ResourceFunction["RandomBins"][Subsets[Range[9], {2}], 3]
Out[4]=

Version History

  • 1.0.0 – 01 September 2021

Related Resources

License Information