Last active
August 18, 2024 21:05
-
-
Save arxdsilva/8caeca47b126a290c4562a25464895e8 to your computer and use it in GitHub Desktop.
Golang - How to generate a random Token
This file contains 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 | |
// https://play.golang.org/p/5VsRVVtyo-J | |
import ( | |
"crypto/rand" | |
"fmt" | |
) | |
func tokenGenerator() string { | |
b := make([]byte, 4) | |
rand.Read(b) | |
return fmt.Sprintf("%x", b) | |
} | |
func main() { | |
a := tokenGenerator() | |
fmt.Println(a) | |
} |
Thanks, this is perfect. :-)
I have also been looking for it, thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this algorithm.