In Max, there are a large number of objects that let you scramble and remix lists of items in interesting ways. Because Max is music focused, a lot of your operations revolve around working with permanent sets. Defining a scale of possible notes doesn’t do you much good if your system is able to randomly select F# 300 times in a row. Max provides the Urn object for this purpose, a ‘grab bag’ for collections. Given a number range, urn returns a member every time it’s triggered. It’s unable to produce the same number again until all other members have been selected.
var urn = new Urn(); var items = ['mice','dogs','tigers','cats']; urn.grab(items); //--> 'dogs' urn.grab(items); //--> 'tigers' urn.grab(items); //--> 'mice' urn.grab(items); //--> 'cats' //throw a different array into the same object //one urn tracks all keys in parallel var junk = ['maggie','lisa','bart']; urn.grab(junk); //--> 'maggie' urn.grab(junk); //--> 'bart' urn.grab(junk); //--> 'lisa' urn.grab(junk); //--> 'lisa' urn.grab(junk); //--> 'maggie' urn.grab(junk); //--> 'bart'
The only missing feature is preventing the end of one sequence being the same as the beginning of the next. Notice the two ‘lisa’s in a row in the above example. Each full round of urn grabs are managed independently.
Grab urnie.js over on the github: https://github.com/jackaperkins/urnie