// class of a SuperCollider pattern specifying a stream which

// selects randomly from a list of elements without repeating

// an element before <memSize> others have occured

 

PavoidN : ListPattern {

   var <>memSize;

 

   *new { arg list, repeats=1, memSize=1;

      ^super.new(list, repeats).memSize_(memSize)

   }

 

   embedInStream { arg inval;

      var nlast=[], allowed, thisVal, memVal;

 

      repeats.value.do({

         allowed = list.difference(nlast);

         thisVal = allowed.choose;

         nlast = nlast.addFirst(thisVal).keep(memSize.value);

         inval = thisVal.embedInStream(inval);

      });

      ^inval;

   }

}