mirror of
https://codeberg.org/scip/gfn.git
synced 2025-12-16 18:30:57 +01:00
initial commit
This commit is contained in:
36
generate.go
Normal file
36
generate.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
fn "github.com/s0rg/fantasyname"
|
||||
)
|
||||
|
||||
func Generate(count int, code string) ([]string, error) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
reg := map[string]int{}
|
||||
|
||||
gen, err := fn.Compile(code, fn.Collapse(true))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not compile FN code:", err)
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
name := gen.String()
|
||||
if !exists(reg, name) {
|
||||
reg[name] = 1
|
||||
}
|
||||
}
|
||||
|
||||
names := make([]string, len(reg))
|
||||
|
||||
i := 0
|
||||
for k, _ := range reg {
|
||||
names[i] = k
|
||||
i++
|
||||
}
|
||||
|
||||
return names, nil
|
||||
}
|
||||
Reference in New Issue
Block a user