To generate a random password with numbers in Go, you can use the math/rand package to generate random numbers and strings. Here is an example function that generates a password with a given length and at least one digit:
main.go546 chars21 lines
This function generates a password of a given length by selecting random characters from a pool of letters and digits. It then adds one random digit to the password and swaps it with a non-digit character to ensure that there is at least one digit in the password.
You can call this function like this:
main.go53 chars3 lines
This will generate a random password with 12 characters, including at least one digit.
gistlibby LogSnag