All checks were successful
		
		
	
	test / test (push) Successful in 42s
				
			## Pull Request template Please, go through these steps before clicking submit on this PR. 1. Give a descriptive title to your PR. 2. Provide a description of your changes. 3. Make sure you have some relevant tests. 4. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if applicable). **PLEASE REMOVE THIS TEMPLATE BEFORE SUBMITTING** Reviewed-on: #369 Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru> Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
		
			
				
	
	
		
			21 lines
		
	
	
		
			530 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			530 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package jitter provides a random jitter
 | |
| package jitter
 | |
| 
 | |
| import (
 | |
| 	"time"
 | |
| 
 | |
| 	"go.unistack.org/micro/v3/util/rand"
 | |
| )
 | |
| 
 | |
| // Random returns a random time to jitter with max cap specified
 | |
| func Random(d time.Duration) time.Duration {
 | |
| 	var rng rand.Rand
 | |
| 	v := rng.Float64() * float64(d.Nanoseconds())
 | |
| 	return time.Duration(v)
 | |
| }
 | |
| 
 | |
| func RandomInterval(minTime, maxTime time.Duration) time.Duration {
 | |
| 	var rng rand.Rand
 | |
| 	return time.Duration(rng.Int63n(maxTime.Nanoseconds()-minTime.Nanoseconds())+minTime.Nanoseconds()) * time.Nanosecond
 | |
| }
 |