Created
March 19, 2021 15:38
-
-
Save Colk-tech/93d29677d9349d99b766f44ee2c3ac21 to your computer and use it in GitHub Desktop.
ランダムで4桁の16進数を生成します
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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