code: function bound(val, min, max) {
      // trim the value to be within min..max (if min..max are specified)
      val = (min !== undefined)? Math.max(val, min) : val;
      val = (max !== undefined)? Math.min(val, max) : val;
      return val ;
  }
docs: useful stuff for random timeseries.