code: func (r *rangeAllocator) nextFreePort() int {
  	r.lock.Lock()
  	defer r.lock.Unlock()
  
  	// choose random port
  	j := r.rand.Intn(r.Size)
  	if b := r.used.Bit(j); b == 0 {
  		r.used.SetBit(&r.used, j, 1)
  		return j + r.Base
  	}
  
  	// search sequentially
  	for i := j + 1; i < r.Size; i++ {
  		if b := r.used.Bit(i); b == 0 {
  			r.used.SetBit(&r.used, i, 1)
  			return i + r.Base
  		}
  	}
  	for i := 0; i < j; i++ {
  		if b := r.used.Bit(i); b == 0 {
  			r.used.SetBit(&r.used, i, 1)
  			return i + r.Base
  		}
  	}
  	return -1
  }
docs: // nextFreePort finds a free port, first picking a random port. if that port is already in use
  // then the port range is scanned sequentially until either a port is found or the scan completes
  // unsuccessfully. an unsuccessful scan returns a port of -1.