Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package randomvalues
import (
"math/rand"
"sync"
"time"
)
type NonCryptoGenerator struct {
characters string
*rand.Rand
*sync.Mutex
}
// Only set seed when you need a non-random value
func NewNonCryptoGenerator(allowedchars string, seed int64) NonCryptoGenerator {
if len(allowedchars) == 0 {
allowedchars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
}
instance := NonCryptoGenerator{
characters: allowedchars,
}
if seed != 0 {
instance.Rand = rand.New(rand.NewSource(seed))
}else{
instance.Rand = rand.New(rand.NewSource(time.Now().UnixMilli()))
}
instance.Mutex = &sync.Mutex{}
return instance
}
func (g *NonCryptoGenerator) GetString(length int) (string) {
g.Lock()
defer g.Unlock()
result := make([]byte, length)
for i := 0; i < length; i++ {
num := g.Intn(len(g.characters))
result[i] = g.characters[num]
}
return string(result)
}