-
Notifications
You must be signed in to change notification settings - Fork 0
/
passengeraspect.go
56 lines (43 loc) · 989 Bytes
/
passengeraspect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package generators
import (
"bufio"
"fmt"
"math/rand"
"strings"
"github.com/hculpan/travtools/pkg/embed"
)
var passengerAspects []string = make([]string, 0)
func initPassengerAspects() error {
if len(passengerAspects) > 0 {
return nil
}
aspects, err := embed.ReadDataFile("passenger_aspects.txt")
if err != nil {
return err
}
scanner := bufio.NewScanner(strings.NewReader(string(aspects)))
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line)
passengerAspects = append(passengerAspects, line)
}
return nil
}
func option(choices []string, weights []int, max int) string {
selected := rand.Intn(max) + 1
for i := range weights {
selected -= weights[i]
if selected <= 0 {
return choices[i]
}
}
return "error in option()"
}
func GeneratePassengerAspect() string {
if err := initPassengerAspects(); err != nil {
fmt.Println(err)
return err.Error()
}
aspect := passengerAspects[rand.Intn(len(passengerAspects))]
return aspect
}