code: func (s *adaptiveSampler) Sample() bool {
  	// adjust sampling rate whenever sample size is reached.
  	var currentRate int
  	if atomic.AddUint32(&s.counter, 1) == s.sampleSize { // exact match prevents
  		atomic.StoreUint32(&s.counter, 0) // race is ok
  		s.Lock()
  		{
  			d := time.Since(s.start).Seconds()
  			r := float64(s.sampleSize) / d
  			currentRate = int((float64(s.maxSamplingRate) * adaptiveUpperBoundFloat) / r)
  			if currentRate > adaptiveUpperBoundInt {
  				currentRate = adaptiveUpperBoundInt
  			} else if currentRate < 1 {
  				currentRate = 1
  			}
  			s.start = time.Now()
  		}
  		s.Unlock()
  		atomic.StoreInt64(&s.lastRate, int64(currentRate))
  	} else {
  		currentRate = int(atomic.LoadInt64(&s.lastRate))
  	}
  
  	// currentRate is never zero.
  	return currentRate == adaptiveUpperBoundInt || rand.Intn(adaptiveUpperBoundInt) < currentRate
  }
docs: // Sample implementation for adaptive rate