golang学习---练习1

第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?


  1. 每个激活码唯一
  2. 200个激活码之间不能有关联(不能根据一个推断出另外一个)
  3. 纯英文字符(url合法字符)

解答
随机数 + 时间戳(纳秒)->base64

package main
import (
    "fmt"
    "math/rand"
    "time"
    "encoding/base64"
)

func main()  {
    for i := 0; i < 20; i++ {
        //获取随机数
        randNum := rand.Int()
        //获取纳秒
        t := time.Now().UnixNano()
        result := fmt.Sprint(randNum) + fmt.Sprint(t)
        encoded := base64.StdEncoding.EncodeToString([]byte(result))
        fmt.Println(encoded)

    }
}
NTU3NzAwNjc5MTk0Nzc3OTQxMDE0NDU5MzA2MTgwMjc5MDc1Njc=
ODY3NDY2NTIyMzA4MjE1MzU1MTE0NDU5MzA2MTgwMjc5NDA1NDY=
NjEyOTQ4NDYxMTY2NjE0NTgyMTE0NDU5MzA2MTgwMjc5NDMxNTk=
NDAzNzIwMDc5NDIzNTAxMDA1MTE0NDU5MzA2MTgwMjc5NDUwNzE=
MzkxNjU4OTYxNjI4NzExMzkzNzE0NDU5MzA2MTgwMjc5NDY5MDU=
NjMzNDgyNDcyNDU0OTE2NzMyMDE0NDU5MzA2MTgwMjc5NDg2NTQ=
NjA1Mzk0NjQ3NjMyOTY5NzU4MTQ0NTkzMDYxODAyNzk1MDMwMA==
MTQ0MzYzNTMxNzMzMTc3NjE0ODE0NDU5MzA2MTgwMjc5NTIwNzQ=
ODk0Mzg1OTQ5MTgzMTE3MjE2MTQ0NTkzMDYxODAyNzk1MzgxMw==
Mjc3NTQyMjA0MDQ4MDI3OTQ0OTE0NDU5MzA2MTgwMjc5NTU1MzA=
NDc1MTk5Nzc1MDc2MDM5ODA4NDE0NDU5MzA2MTgwMjc5Njc1NjQ=
NzUwNDUwNDA2NDI2MzY2OTI4NzE0NDU5MzA2MTgwMjc5Njk0MzY=
MTk3NjIzNTQxMDg4NDQ5MTU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