You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.0 KiB
133 lines
3.0 KiB
4 months ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"math"
|
||
|
"math/rand"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func checkOne(ctx context.Context, result string, value string) bool {
|
||
|
log.Println("checkOne: ", result, value)
|
||
|
if strings.Contains(result, value) {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
//var res []entity.GameCdKey
|
||
|
//err := dao.GameCdKey.Ctx(ctx).Where("code=?", value).Scan(&res)
|
||
|
//if err != nil || (res != nil && res[0].Id > -1) {
|
||
|
// return true
|
||
|
//}
|
||
|
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func saveCdKey(ctx context.Context, id int, value string) {
|
||
|
//res, err := dao.GameCdKey.Ctx(ctx).Insert(&do.GameCdKey{Code: value, ConfigId: id})
|
||
|
//if err != nil {
|
||
|
// log.Printf("saveCdKey value: %s, id: %d, err: %v", value, id, err)
|
||
|
//} else {
|
||
|
// log.Println("saveCdKey res: ", res)
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
func getPreValue(id int, charset string) string {
|
||
|
charsetLen := len(charset)
|
||
|
preValue := ""
|
||
|
for {
|
||
|
preValue = charset[id%charsetLen:id%charsetLen+1] + preValue
|
||
|
if id/charsetLen == 0 {
|
||
|
break
|
||
|
}
|
||
|
id = id / charsetLen
|
||
|
}
|
||
|
|
||
|
return preValue
|
||
|
}
|
||
|
func randomGenerate(ctx context.Context, preName string, id, num int, isSave bool) {
|
||
|
charset := "0123456789abcdefghijklmnopqrstuvwxyz"
|
||
|
//lenfrom := 10
|
||
|
//lento := 10
|
||
|
//result := ""
|
||
|
//index := -1
|
||
|
preValue := getPreValue(100900000, charset)
|
||
|
log.Println("randomGenerate: ", preValue, preName, num)
|
||
|
//for i := num - 1; i >= 0; {
|
||
|
// log.Println("randomGenerate: ", index, i)
|
||
|
// if index == i {
|
||
|
// continue
|
||
|
// }
|
||
|
// index = i
|
||
|
// value := generateOne(charset, lenfrom, lento)
|
||
|
// log.Println("generateOne: ", value)
|
||
|
// a := checkOne(ctx, result, value)
|
||
|
// if a == true {
|
||
|
// index = -1
|
||
|
// continue
|
||
|
// }
|
||
|
//
|
||
|
// i--
|
||
|
// result += value + "\r"
|
||
|
// if isSave {
|
||
|
// saveCdKey(ctx, id, value)
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
//if err := os.WriteFile(fmt.Sprintf("./%s%d.xlsx", preName, id), []byte(result), 0666); err != nil {
|
||
|
// log.Fatal(err)
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
3 months ago
|
//ctx := gctx.New()
|
||
|
//preName := fmt.Sprintf("code%d_", time.Now().Unix())
|
||
|
//randomGenerate(ctx, preName, 0, 10, true)
|
||
|
channel := "000000000000"
|
||
|
accountName := "lq00001000000000000"
|
||
|
if !strings.HasPrefix(accountName, channel) {
|
||
|
log.Println("not in ", accountName, channel)
|
||
|
return
|
||
|
}
|
||
|
log.Println("has in ", accountName, channel)
|
||
4 months ago
|
}
|
||
|
|
||
|
func generateOne(charset string, lenfrom, lento int) string {
|
||
|
result := ""
|
||
|
log.Println("generateOne: ", charset, lenfrom, lento)
|
||
|
if (lenfrom <= lento) && (len(charset) > 0) && (lenfrom >= 0) {
|
||
|
length := math.Round(randomFloat(lenfrom, lento))
|
||
|
for {
|
||
|
log.Println("generateOne: ", charset, lenfrom, lento)
|
||
|
if float64(len(result)) < length {
|
||
|
Float64Data := math.Floor(rand.Float64() * float64(len(charset)))
|
||
|
Int, _ := strconv.Atoi(fmt.Sprint(Float64Data))
|
||
|
result += string(getChar(charset, Int))
|
||
|
} else {
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
func getChar(str string, index int) rune {
|
||
|
return []rune(str)[index]
|
||
|
}
|
||
|
|
||
|
// float
|
||
|
func randomFloat(min, max int) float64 {
|
||
|
if max == min {
|
||
|
return float64(max)
|
||
|
}
|
||
|
return decimal(rand.Float64()*(float64(max)-float64(min)) + float64(min))
|
||
|
}
|
||
|
|
||
|
func decimal(v float64) float64 {
|
||
|
val, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", v), 64)
|
||
|
return val
|
||
|
}
|