diff options
| author | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-11-02 15:27:18 +0800 |
| commit | e9c24f4af7ed56760f6db7941827d09f6db9020b (patch) | |
| tree | 62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/vendor/github.com/labstack/gommon/random | |
| parent | 58d5e7cfda4781d8a57ec52aefd02983835c301a (diff) | |
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/labstack/gommon/random')
| -rw-r--r-- | teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go b/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go new file mode 100644 index 0000000..482d052 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/labstack/gommon/random/random.go @@ -0,0 +1,48 @@ +package random + +import ( + "math/rand" + "strings" + "time" +) + +type ( + Random struct { + } +) + +// Charsets +const ( + Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + Lowercase = "abcdefghijklmnopqrstuvwxyz" + Alphabetic = Uppercase + Lowercase + Numeric = "0123456789" + Alphanumeric = Alphabetic + Numeric + Symbols = "`" + `~!@#$%^&*()-_+={}[]|\;:"<>,./?` + Hex = Numeric + "abcdef" +) + +var ( + global = New() +) + +func New() *Random { + rand.Seed(time.Now().UnixNano()) + return new(Random) +} + +func (r *Random) String(length uint8, charsets ...string) string { + charset := strings.Join(charsets, "") + if charset == "" { + charset = Alphanumeric + } + b := make([]byte, length) + for i := range b { + b[i] = charset[rand.Int63()%int64(len(charset))] + } + return string(b) +} + +func String(length uint8, charsets ...string) string { + return global.String(length, charsets...) +} |
