diff --git a/app.go b/app.go index 917edbc..b873c9e 100644 --- a/app.go +++ b/app.go @@ -1,6 +1,6 @@ /* * @Author: NorthCity1984 - * @LastEditTime: 2022-04-03 09:31:39 + * @LastEditTime: 2022-04-04 16:09:13 * @Description: * @Website: https://grimoire.cn * Copyright (c) NorthCity1984 All rights reserved. @@ -8,14 +8,28 @@ package main import ( + // "githuh" + "fmt" - "math" + + "gitee.com/NorthCityChen/stl-go/randoom" ) func main() { - // ans := math.Exp2(0) - ans := math.Sqrt(-8) - // ans2 := math1.Sqrt(-8) - fmt.Println(ans) - // fmt.Println(ans2) + // // ans := math.Exp2(0) + // ans := math.Sqrt(-8) + // // ans2 := math1.Sqrt(-8) + // fmt.Println(ans) + // // fmt.Println(ans2) + // string + // queue + // queue + // random.RandStringBytesMaskImprSrcSB(5) + // fmt.Println(r) + // ret := randoom.RandStr(45) + fmt.Println(randoom.RandStr(45)) + fmt.Println(randoom.RandStr(45)) + fmt.Println(randoom.RandStr(45)) + fmt.Println(randoom.RandStr(45)) + fmt.Println(randoom.RandStr(45)) } diff --git a/randoom/random.go b/randoom/random.go new file mode 100644 index 0000000..8fbec02 --- /dev/null +++ b/randoom/random.go @@ -0,0 +1,40 @@ +/* + * @Author: NorthCity1984 + * @LastEditTime: 2022-04-04 16:10:11 + * @Description: + * @Website: https://grimoire.cn + * Copyright (c) NorthCity1984 All rights reserved. + */ +package randoom + +import ( + "math/rand" + "strings" + "time" +) + +const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +const ( + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + str.WriteByte(letterBytes[idx]) + i-- + } + cache >>= letterIdxBits + remain-- + } + return str.String() +}