Skip to content

Instantly share code, notes, and snippets.

@Colk-tech
Created March 19, 2021 15:38
Show Gist options
  • Select an option

  • Save Colk-tech/93d29677d9349d99b766f44ee2c3ac21 to your computer and use it in GitHub Desktop.

Select an option

Save Colk-tech/93d29677d9349d99b766f44ee2c3ac21 to your computer and use it in GitHub Desktop.
ランダムで4桁の16進数を生成します
package main
import (
"fmt"
"math/rand"
"time"
)
const letters = "0123456789ABCDEF"
func main() {
fmt.Println(RandString(4))
}
func RandString(length int) string {
rand.Seed(time.Now().UnixNano())
b := make([]byte, length)
for i := range b {
b[i] = letters[int(rand.Int63()%int64(len(letters)))]
}
return string(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment