-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbs_composite.go
More file actions
43 lines (41 loc) · 1.17 KB
/
bs_composite.go
File metadata and controls
43 lines (41 loc) · 1.17 KB
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
package main
import (
"fmt"
"math/rand"
"strconv"
"strings"
)
var bs_composite = map[string]func(bs Bs) (string, error){
"num": func(bs Bs) (string, error) {
arg_parsed := strings.Split(bs.Args[1], "to")
min, _ := strconv.Atoi(arg_parsed[0])
max, _ := strconv.Atoi(arg_parsed[1])
return strconv.Itoa(rand.Intn(max-min) + min), nil
},
"rel": func(bs Bs) (string, error) {
return strconv.Itoa(rand.Intn(int(bs.RelationshipTable.Volume))), nil
},
"val": func(bs Bs) (string, error) {
return bs.Args[1], nil
},
"timestamp_epoch": func(bs Bs) (string, error) {
return strconv.Itoa(rand.Intn(1731414911)), nil
},
"fullname": func(bs Bs) (string, error) {
r_0 := rand.Intn(len(bsa["first_name"]))
r_1 := rand.Intn(len(bsa["last_name"]))
r := fmt.Sprintf("%s %s", bsa["first_name"][r_0], bsa["last_name"][r_1])
return r, nil
},
"bool": func(bs Bs) (string, error) {
factor := 0.5
if len(bs.Args) > 1 {
factor, _ = strconv.ParseFloat(bs.Args[1], 64)
}
r := "FALSE"
if rand.Float64() < factor {
r = "TRUE"
}
return r, nil
},
}