mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
tests: Fix rare test crash (#4175)
Fix rare test crash by improving the randomness logic.
This commit is contained in:
committed by
Harshavardhana
parent
e5b2e25caf
commit
9b58a669e5
@@ -2361,3 +2361,28 @@ func getEndpointsLocalAddr(endpoints EndpointList) string {
|
||||
|
||||
return globalMinioHost + ":" + globalMinioPort
|
||||
}
|
||||
|
||||
// fetches a random number between range min-max.
|
||||
func getRandomRange(min, max int, seed int64) int {
|
||||
// special value -1 means no explicit seeding.
|
||||
if seed != -1 {
|
||||
rand.Seed(seed)
|
||||
}
|
||||
return rand.Intn(max-min) + min
|
||||
}
|
||||
|
||||
// Randomizes the order of bytes in the byte array
|
||||
// using Knuth Fisher-Yates shuffle algorithm.
|
||||
func randomizeBytes(s []byte, seed int64) []byte {
|
||||
// special value -1 means no explicit seeding.
|
||||
if seed != -1 {
|
||||
rand.Seed(seed)
|
||||
}
|
||||
n := len(s)
|
||||
var j int
|
||||
for i := 0; i < n-1; i++ {
|
||||
j = i + rand.Intn(n-i)
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user