code: func (c *Counter) Next(n int) int {
  	if n <= 0 {
  		panic("n must be greater than 0")
  	}
  
  	for {
  		current := atomic.LoadInt32(&c.index)
  		logger.Debugf("Current index: %d", current)
  
  		i := int(current)
  		if i == -1 {
  			// Choose a random index the first time
  			i = rand.Intn(n)
  		} else {
  			i++
  			if i >= n {
  				i = 0
  			}
  		}
  
  		if atomic.CompareAndSwapInt32(&c.index, current, int32(i)) {
  			logger.Debugf("Set the counter to %d", i)
  			return i
  		}
  
  		logger.Debugf("Another thread has already incremented the counter. Trying again...")
  	}
  }
docs: // Next increments the counter. If the counter reaches n then
  // the counter is reset to 0. Note: n must be greater than 0 or else
  // a panic will result.