Function Repository Resource:

RandomIntegerPartition

Source Notebook

Generate a random partition of an integer

Contributed by: Wolfram Staff

ResourceFunction["RandomIntegerPartition"][n]

generates a random partition of the integer n into smaller integers.

ResourceFunction["RandomIntegerPartition"][n,k]

generates k partitions.

Details

For n>1000, ResourceFunction["RandomIntegerPartition"] uses a nonuniform method, and may not return all possible partitions with equal likelihood.

Examples

Basic Examples (2) 

Generate a random partition of the integer 5:

In[1]:=
ResourceFunction["RandomIntegerPartition"][5]
Out[1]=

Generate multiple random partitions:

In[2]:=
ResourceFunction["RandomIntegerPartition"][13, 3]
Out[2]=

Scope (2) 

Generate a random partition of a medium-sized integer:

In[3]:=
ResourceFunction["RandomIntegerPartition"][500]
Out[3]=

Generate three partitions of 20000:

In[4]:=
ResourceFunction["RandomIntegerPartition"][20000, 3]
Out[4]=

Version History

  • 1.0.0 – 29 March 2022

Related Resources

License Information