This library assists in generating random strings based on specific characteristics. You can create random strings consisting of alphanumeric characters, letters only, digits only, special characters, or even a custom character set.
- Generate strings with alphanumeric, letters only, digits only, or special characters.
- Ability to disable uppercase, lowercase, or numeric characters.
- Option to use a custom character set.
go get -u github.com/necmettindev/randomstring
Below are different scenarios demonstrating how to use the randomstring
package:
Generate a string of length 10 using the default alphanumeric characters:
package main
import (
"fmt"
"github.com/necmettindev/randomstring"
)
func main() {
opts := randomstring.GenerationOptions{
Length: 10,
}
result, _ := randomstring.GenerateString(opts)
fmt.Println(result)
}
For instance, to generate a string containing letters only:
opts := randomstring.GenerationOptions{
Length: 10,
DisableNumeric: true,
}
result, _ := randomstring.GenerateString(opts)
fmt.Println(result)
Generate a string with enabled special characters:
opts := randomstring.GenerationOptions{
Length: 15,
EnableSpecialCharacter: true,
}
result, _ := randomstring.GenerateString(opts)
fmt.Println(result)
Generate a string with your own custom character set:
opts := randomstring.GenerationOptions{
Length: 12,
CustomCharset: "abcXYZ789",
}
result, _ := randomstring.GenerateString(opts)
fmt.Println(result) // Produces a string consisting only of 'a', 'b', 'c', 'X', 'Y', 'Z', '7', '8', '9'.
If you wish to contribute to this project, please first open an issue or pick up an existing one. Then make your contribution and submit a pull request.
This project is licensed under the MIT License.