49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
"time"
|
|
)
|
|
|
|
// Generates a random integer in the range (min, max)
|
|
func RandInt(min, max int) int {
|
|
n, _ := rand.Int(rand.Reader, big.NewInt(int64(max-min)))
|
|
return int(n.Int64()) + min
|
|
}
|
|
|
|
// Get the current time in milliseconds
|
|
func GetCurrentTimeMillis() int64 {
|
|
return time.Now().UnixNano() / int64(time.Millisecond) // Convert nanoseconds to milliseconds
|
|
}
|
|
|
|
// IsAlpha checks if the string contains only alphabetic characters
|
|
func IsAlpha(s string) bool {
|
|
for _, r := range s {
|
|
if !('a' <= r && r <= 'z') && !('A' <= r && r <= 'Z') {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// IsDigit checks if the string contains only digits
|
|
func IsDigit(s string) bool {
|
|
for _, r := range s {
|
|
if !(r >= '0' && r <= '9') {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// IsHex checks if the string is a valid hexadecimal representation
|
|
func IsHex(s string) bool {
|
|
for _, r := range s {
|
|
if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|