2024-04-26 19:30:35 +00:00
|
|
|
package gofakeit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Gamertag will generate a random video game username
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func Gamertag() string { return gamertag(globalFaker.Rand) }
|
|
|
|
|
|
|
|
// Gamertag will generate a random video game username
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func (f *Faker) Gamertag() string { return gamertag(f.Rand) }
|
|
|
|
|
|
|
|
func gamertag(r *rand.Rand) string {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str := ""
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
num := number(r, 1, 4)
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
switch num {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
case 1:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str = fmt.Sprintf("%s%ser", title(nounConcrete(r)), title(verbAction(r)))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
case 2:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(r)), title(animal(r)))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
case 3:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(r)), title(nounConcrete(r)))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
case 4:
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str = fmt.Sprintf("%s%s", title(fruit(r)), title(adjectiveDescriptive(r)))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Randomly determine if we should add a number
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if r.Intn(3) == 1 {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str += digitN(r, uint(number(r, 1, 3)))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any spaces
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
str = strings.Replace(str, " ", "", -1)
|
|
|
|
|
|
|
|
return str
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dice will generate a random set of dice
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func Dice(numDice uint, sides []uint) []uint { return dice(globalFaker.Rand, numDice, sides) }
|
|
|
|
|
|
|
|
// Dice will generate a random set of dice
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
func (f *Faker) Dice(numDice uint, sides []uint) []uint { return dice(f.Rand, numDice, sides) }
|
|
|
|
|
|
|
|
func dice(r *rand.Rand, numDice uint, sides []uint) []uint {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
dice := make([]uint, numDice)
|
|
|
|
|
|
|
|
// If we dont have any sides well set the sides to 6
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if len(sides) == 0 {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
sides = []uint{6}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range dice {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
// If sides[i] doesnt exist use the first side
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if len(sides)-1 < i {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
dice[i] = uint(number(r, 1, int(sides[0])))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
} else {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
dice[i] = uint(number(r, 1, int(sides[i])))
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dice
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func addGameLookup() {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
AddFuncLookup("gamertag", Info{
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
Display: "Gamertag",
|
|
|
|
|
|
|
|
Category: "game",
|
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Description: "User-selected online username or alias used for identification in games",
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
Example: "footinterpret63",
|
|
|
|
|
|
|
|
Output: "string",
|
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
return gamertag(r), nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
AddFuncLookup("dice", Info{
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
Display: "Dice",
|
|
|
|
|
|
|
|
Category: "game",
|
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Description: "Small, cube-shaped objects used in games of chance for random outcomes",
|
2024-07-24 23:45:04 +00:00
|
|
|
|
|
|
|
Example: "[5, 2, 3]",
|
|
|
|
|
|
|
|
Output: "[]uint",
|
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Params: []Param{
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
{Field: "numdice", Display: "Number of Dice", Type: "uint", Default: "1", Description: "Number of dice to roll"},
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
{Field: "sides", Display: "Number of Sides", Type: "[]uint", Default: "[6]", Description: "Number of sides on each dice"},
|
|
|
|
},
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
Generate: func(r *rand.Rand, m *MapParams, info *Info) (any, error) {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
numDice, err := info.GetUint(m, "numdice")
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if err != nil {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
return nil, err
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sides, err := info.GetUintArray(m, "sides")
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
if err != nil {
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
return nil, err
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dice(r, numDice, sides), nil
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
},
|
|
|
|
})
|
2024-07-24 23:45:04 +00:00
|
|
|
|
2024-04-26 19:30:35 +00:00
|
|
|
}
|