You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ctxutil.go
    path of file: ./repos/FerretDB/internal/util/ctxutil
    
    the code of the file until where you have to start completion: // Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unl
    
func durationWithJitter(cap time.Duration, attempt int64) time.Duration {
	const base = 100      // ms
	const minDuration = 3 // ms

	capDuration := cap.Milliseconds()

	if attempt < 1 {
		panic("attempt must be nonzero positive number")
	}

	if capDuration <= minDuration {
		panic(fmt.Sprintf("cap must be larger than min duration (%dms)", minDuration))
	}

	// calculate base backoff based on base duration and amount of attempts
	backoff := float64(base * math.Pow(2, float64(attempt)))
	// cap is a max limit of possible durations returned
	maxDuration := int64(math.Min(float64(capDuration), backoff))

	// Math/rand is good enough because we don't need the randomness to be cryptographically secure.
	sleep := rand.Int63n(maxDuration-minDuration) + minDuration

	return time.Duration(sleep) * time.Millisecond
}