Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package generators
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
type KenkuArrays struct {
|
||||
Nm1 []string `json:"nm1"`
|
||||
Nm2 []string `json:"nm2"`
|
||||
Nm3 []string `json:"nm3"`
|
||||
}
|
||||
|
||||
func LoadKenkuArrays(path string) (KenkuArrays, error) {
|
||||
var arrays KenkuArrays
|
||||
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 GenerateKenkuNames(arr *KenkuArrays) []string {
|
||||
names := make([]string, 0, 10)
|
||||
nm1 := make([]string, len(arr.Nm1))
|
||||
nm2 := make([]string, len(arr.Nm2))
|
||||
nm3 := make([]string, len(arr.Nm3))
|
||||
copy(nm1, arr.Nm1)
|
||||
copy(nm2, arr.Nm2)
|
||||
copy(nm3, arr.Nm3)
|
||||
for i := 0; i < 10; i++ {
|
||||
var name string
|
||||
if i < 4 {
|
||||
rnd := rand.Intn(len(nm1))
|
||||
name = nm1[rnd]
|
||||
nm1 = append(nm1[:rnd], nm1[rnd+1:]...)
|
||||
} else if i < 7 {
|
||||
rnd := rand.Intn(len(nm2))
|
||||
name = nm2[rnd]
|
||||
nm2 = append(nm2[:rnd], nm2[rnd+1:]...)
|
||||
} else {
|
||||
rnd := rand.Intn(len(nm3))
|
||||
name = nm3[rnd]
|
||||
nm3 = append(nm3[:rnd], nm3[rnd+1:]...)
|
||||
}
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
Reference in New Issue
Block a user