-
Notifications
You must be signed in to change notification settings - Fork 7
/
strings.go
49 lines (37 loc) · 1.05 KB
/
strings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package rand
import (
"math/rand"
"time"
"variant/compress"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
var random = rand.New(rand.NewSource(time.Now().UnixNano()))
// LStrings 生成指定长度的字符串
func LStrings(length int) string {
b := make([]rune, length)
for i := range b {
b[i] = letters[random.Intn(len(letters))]
}
return string(b)
}
// RStrings 生成随机长度(2-18)的字符串
func RStrings() string {
rand.New(rand.NewSource(time.Now().UnixNano()))
b := make([]rune, rand.Intn(16)+2)
for i := range b {
b[i] = letters[random.Intn(len(letters))]
}
return string(b)
}
// LzwStrings 生成指定长度的字符串,返回 lzw 压缩后的字符串
func LzwStrings(length int) string {
b := LStrings(length)
lzwStrings, _ := compress.LzwCompress([]byte(b), 8)
return lzwStrings
}
// ZstdStrings 生成指定长度的字符串,返回 zstd 压缩后的字符串
func ZstdStrings(length int) string {
b := LStrings(length)
lzwStrings, _ := compress.ZstdCompress(b)
return lzwStrings
}