Initial commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package generators
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
type GenasiArrays struct {
|
||||
Nm1 []string `json:"nm1"`
|
||||
Nm2 []string `json:"nm2"`
|
||||
Nm3 []string `json:"nm3"`
|
||||
Nm4 []string `json:"nm4"`
|
||||
}
|
||||
|
||||
func LoadGenasiArrays(path string) (GenasiArrays, error) {
|
||||
var arrays GenasiArrays
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return arrays, err
|
||||
}
|
||||
defer file.Close()
|
||||
decoder := json.NewDecoder(file)
|
||||
err = decoder.Decode(&arrays)
|
||||
return arrays, err
|
||||
}
|
||||
|
||||
func GenerateGenasiNames(arr GenasiArrays, swearFilter func(string) bool) []string {
|
||||
// Copy slices to avoid mutating the original arrays
|
||||
nm1 := append([]string{}, arr.Nm1...)
|
||||
nm2 := append([]string{}, arr.Nm2...)
|
||||
nm3 := append([]string{}, arr.Nm3...)
|
||||
nm4 := append([]string{}, arr.Nm4...)
|
||||
var names []string
|
||||
for i := 0; i < 12; i++ {
|
||||
var n string
|
||||
if i < 3 {
|
||||
if len(nm1) == 0 {
|
||||
continue
|
||||
}
|
||||
rnd := rand.Intn(len(nm1))
|
||||
n = nm1[rnd]
|
||||
nm1 = append(nm1[:rnd], nm1[rnd+1:]...)
|
||||
} else if i < 6 {
|
||||
if len(nm2) == 0 {
|
||||
continue
|
||||
}
|
||||
rnd := rand.Intn(len(nm2))
|
||||
n = nm2[rnd]
|
||||
nm2 = append(nm2[:rnd], nm2[rnd+1:]...)
|
||||
} else if i < 9 {
|
||||
if len(nm3) == 0 {
|
||||
continue
|
||||
}
|
||||
rnd := rand.Intn(len(nm3))
|
||||
n = nm3[rnd]
|
||||
nm3 = append(nm3[:rnd], nm3[rnd+1:]...)
|
||||
} else {
|
||||
if len(nm4) == 0 {
|
||||
continue
|
||||
}
|
||||
rnd := rand.Intn(len(nm4))
|
||||
n = nm4[rnd]
|
||||
nm4 = append(nm4[:rnd], nm4[rnd+1:]...)
|
||||
}
|
||||
if swearFilter != nil && swearFilter(n) {
|
||||
continue
|
||||
}
|
||||
names = append(names, n)
|
||||
}
|
||||
return names
|
||||
}
|
||||
Reference in New Issue
Block a user