Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Randomly move an item between lists in a collection
ResourceFunction["RandomBinMove"][{bin1,bin2,…}] randomly picks an item in a random bin and moves it to a different bin. |
From a set of four bins with the numbers 1 to 10, randomly move one item:
| In[1]:= |
| Out[2]= |
Try it again:
| In[3]:= |
| Out[3]= |
Make 30 bin moves in sequence:
| In[4]:= |
| Out[4]= |
There are thirty possible ways to move a single item in the bins above:
| In[5]:= |
| Out[5]= | ![]() |
| In[6]:= |
| Out[6]= |
Bins can have repeated items:
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
Bin items can be arbitrary expressions:
| In[9]:= |
| Out[10]= |
Bins must be non-atomic:
| In[11]:= | ![]() |
| Out[12]= |
Bins need not be a List:
| In[13]:= |
| Out[13]= |
| In[14]:= |
| Out[14]= |
With two nested random bin moves, it is possible to get back to the starting bins:
| In[15]:= |
| Out[16]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License