Browse Source

Initial commit

master
Ricardo 2 years ago
commit
e0a4e1251f
Signed by: Dymstro
GPG Key ID: A90945AF5D94F15D
  1. 17
      .gitignore
  2. 14
      LICENSE
  3. 16
      README.md
  4. 3
      go.mod
  5. 31
      main.go

17
.gitignore vendored

@ -0,0 +1,17 @@
# ---> Go
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

14
LICENSE

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified copies of
this license document, and changing it is allowed as long as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

16
README.md

@ -0,0 +1,16 @@
# go-randomstring
Simple go module for generating random strings
## Usage
```
import (
'''
"git.dymstro.nl/Dymstro/go-randomstring"
'''
)
randomstring.Gen(length int, lower bool, upper bool, num bool)
```

3
go.mod

@ -0,0 +1,3 @@
module git.dymstro.nl/Dymstro/go-randomstring
go 1.14

31
main.go

@ -0,0 +1,31 @@
package randomstring
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func Gen(length int, lower bool, upper bool, num bool) string {
r := [3]string{"abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "1234567890",}
chars := []rune("")
if lower {
chars = []rune(string(chars) + r[0])
}
if upper {
chars = []rune(string(chars) + r[1])
}
if num {
chars = []rune(string(chars) + r[2])
}
str := make([]rune, length)
for i := range str {
str[i] = chars[rand.Intn(len(chars))]
}
return string(str)
}
Loading…
Cancel
Save