The first takes the brownian walk and creates a sliding window of four elements (advancing always one element after each window), where the windows are then filtered to contain no duplicates ("distinct" values). For example, if the brownian would produce [100, 99, 100, 99, 98, 99, 97, 95, 96, 97], then the sliding(4) transforms it into [[100, 99, 100, 99], [99, 100, 99, 98], [100, 99, 98, 99], [99, 98, 99, 97], [98, 99, 97, 95], [99, 97, 95, 96], [97, 95, 96, 97]], and the flatMap which is short for map.flatten filters the groups of four elements to contain no duplicates, so [[100, 99], [99, 100, 98], [100, 99, 98], [99, 98, 97], [98, 99, 97, 95], [99, 97, 95, 96], [97, 95, 96]] or flattened [100, 99, 99, 100, 98, 100, 99, 98, 99, 98, 97, 98, 99, 97, 95, 99, 97, 95, 96, 97, 95, 96].
The second produces the wrapped counter 0, 1, 2, ... 11, 0, 1, 2, etc., adds 72 to go into the range of 72 until 84, then randomly shuffles the positions within each group of twelve elements, effectively giving you an "urn" of the twelve pitches of an octave, but always in random order.