GITLAB

aarongao / leyoutu_server

Sign in
  • Sign in
  • Project
  • Files
  • Commits
  • Network
  • Graphs
  • Issues 0
  • Merge Requests 0
  • Wiki
  • leyoutu_server
  • Lib
  • Code.go
  • 128c8d27   upload Browse Code ยป
    aarongao
    2020-01-13 14:26:39 +0800  
Code.go 322 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package Lib

import (
	"fmt"
	"math/rand"
	"strings"
	"time"
)


func SmsCode(width int) string {
	numeric := [10]byte{0,1,2,3,4,5,6,7,8,9}
	r := len(numeric)
	rand.Seed(time.Now().UnixNano())

	var sb strings.Builder
	for i := 0; i < width; i++ {
		fmt.Fprintf(&sb, "%d", numeric[ rand.Intn(r) ])
	}
	return sb.String()
}