MCPcopy Create free account
hub / github.com/Permify/permify / secureRandomFloat64

Function secureRandomFloat64

internal/storage/postgres/utils/common.go:202–210  ·  view source on GitHub ↗

secureRandomFloat64 generates a float64 value in the range [0, 1) using crypto/rand. Optimized version with better error handling and performance.

()

Source from the content-addressed store, hash-verified

200// secureRandomFloat64 generates a float64 value in the range [0, 1) using crypto/rand.
201// Optimized version with better error handling and performance.
202func secureRandomFloat64() float64 {
203 var b [8]byte
204 if _, err := rand.Read(b[:]); err != nil {
205 // Use a fallback random value instead of 0 to maintain jitter
206 return 0.5 // Middle value for consistent jitter behavior
207 }
208 // Use bit shifting instead of division for better performance
209 return float64(binary.BigEndian.Uint64(b[:])) / (1 << 63) / 2.0
210}
211
212// EnsureDBVersion checks the version of the given database connection
213// and returns an error if the version is not supported.

Callers 1

WaitWithBackoffFunction · 0.85

Calls 1

ReadMethod · 0.65

Tested by

no test coverage detected