dengbiao pirms 2 mēnešiem
vecāks
revīzija
54d6c4c4a6
2 mainītis faili ar 16 papildinājumiem un 16 dzēšanām
  1. +5
    -0
      app/hdl/hdl_demo.go
  2. +11
    -16
      app/utils/rand.go

+ 5
- 0
app/hdl/hdl_demo.go Parādīt failu

@@ -7,10 +7,15 @@ import (
"applet/app/utils"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"fmt"
"github.com/gin-gonic/gin"
)

func Demo(c *gin.Context) {
for {
mediumId := utils.GenerateUniqueRandomNumbers(8)
fmt.Println(mediumId)
}
appId := c.DefaultQuery("app_id", "")
masterId := svc.GetMasterId(c)
adUnitId := c.DefaultQuery("adunit_id", "")


+ 11
- 16
app/utils/rand.go Parādīt failu

@@ -32,22 +32,16 @@ func RandNum() string {
}

func GenerateUniqueRandomNumbers(n int) string {
rand.Seed(time.Now().UnixNano()) // 初始化随机种子
numbers := make([]int, n) // 创建一个切片来保存随机数
for i := range numbers {
j := 0
for {
b := rand.Intn(10) // 生成0-9之间的随机数
numbers[i] = b
for _, num := range numbers[:i] {
if num == b {
j++
break
}
}
if j == 0 {
break
}
rand.Seed(time.Now().UnixNano() + rand.Int63()) // 初始化随机种子

numbers := make([]int, 0, n) // 创建一个切片来保存随机数,初始容量为n
used := make(map[int]bool) // 跟踪已使用的数字

for len(numbers) < n {
b := rand.Intn(10) // 生成0-9之间的随机数
if !used[b] {
numbers = append(numbers, b)
used[b] = true
}
}

@@ -55,5 +49,6 @@ func GenerateUniqueRandomNumbers(n int) string {
for _, v := range numbers {
numbersStr += strconv.Itoa(v)
}

return numbersStr
}

Notiek ielāde…
Atcelt
Saglabāt