Skip to content

Instantly share code, notes, and snippets.

@arxdsilva
Last active May 22, 2024 03:06
Show Gist options
  • Save arxdsilva/8caeca47b126a290c4562a25464895e8 to your computer and use it in GitHub Desktop.
Save arxdsilva/8caeca47b126a290c4562a25464895e8 to your computer and use it in GitHub Desktop.
Golang - How to generate a random Token
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)
}
@andysteve
Copy link

Thank you for this algorithm.

@PaulWheatcroft
Copy link

Thanks, this is perfect. :-)

@kiruiaaron
Copy link

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