Skip to content

Commit

Permalink
Bring random package into the project
Browse files Browse the repository at this point in the history
  • Loading branch information
BenOvermyer committed Apr 15, 2019
1 parent 02af437 commit e3e06a8
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 99 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ require (
github.com/go-chi/chi v4.0.2+incompatible
github.com/ironarachne/heraldry v0.0.0-20190325172346-07bf7eeae990
github.com/ironarachne/naminglanguage v0.0.0-20190326140911-90c4c9184634
github.com/ironarachne/random v0.0.0-20190325170425-9caaa0b3405a
github.com/ironarachne/utility v0.0.0-20181021125830-32a6c250e33b
github.com/juju/testing v0.0.0-20190415054131-a282c42ba059 // indirect
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a // indirect
golang.org/x/net v0.0.0-20190415100556-4a65cf94b679 // indirect
golang.org/x/sys v0.0.0-20190415145633-3fd5a3612ccd // indirect
golang.org/x/tools v0.0.0-20190415203136-744a51dd885a // indirect
golang.org/x/tools v0.0.0-20190415205951-2e9de471ebd3 // indirect
)
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxm
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
github.com/iris-contrib/formBinder v0.0.0-20190104093907-fbd5963f41e1/go.mod h1:i8kTYUOEstd/S8TG0ChTXQdf4ermA/e8vJX0+QruD9w=
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
github.com/ironarachne/heraldry v0.0.0-20190325172346-07bf7eeae990 h1:mekG9VvMDcbEVif9E43R8eOsWz3WQBUvd+i89Ur06XM=
github.com/ironarachne/heraldry v0.0.0-20190325172346-07bf7eeae990/go.mod h1:gQEvdxW/dafJgeFEjoOu8jKtk6DW2wqHBAM95cb5+48=
github.com/ironarachne/naminglanguage v0.0.0-20190326140911-90c4c9184634 h1:p9Rg9Xt34r+oEmZ+sWz49ef2dCVTCN0z+cHsJaoo6eg=
github.com/ironarachne/naminglanguage v0.0.0-20190326140911-90c4c9184634/go.mod h1:iQlQfXBFCQzoRgnBym09tjmTfI3gRBmxactk18WNP0A=
Expand Down Expand Up @@ -64,8 +63,7 @@ golang.org/x/sys v0.0.0-20190415145633-3fd5a3612ccd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190325161752-5a8dccf5b48a/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190415154727-2b5498619ef1/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190415203136-744a51dd885a/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190415205951-2e9de471ebd3/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
Expand Down
26 changes: 13 additions & 13 deletions pkg/character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package character
import (
"math/rand"

"github.com/ironarachne/random"
"github.com/ironarachne/utility"
"github.com/ironarachne/world/pkg/random"

"github.com/ironarachne/world/pkg/culture"
)
Expand Down Expand Up @@ -120,7 +120,7 @@ func getAgeFromParents(parents Couple) (int, string) {
}

func randomOrientation() string {
return random.ItemFromThresholdMap(orientations)
return random.StringFromThresholdMap(orientations)
}

func (character Character) randomHeight() int {
Expand Down Expand Up @@ -170,7 +170,7 @@ func (character Character) randomFacialHair() string {

hairChance := rand.Intn(10)
if hairChance > 8 {
return random.Item(character.Culture.Appearance.FacialHairStyles)
return random.String(character.Culture.Appearance.FacialHairStyles)
}

return "none"
Expand All @@ -180,36 +180,36 @@ func (character Character) randomFacialHair() string {
func Generate() Character {
char := Character{}

char.Gender = random.Item(genders)
char.Gender = random.String(genders)
char.Culture = culture.Generate()

char.FirstName, char.LastName = getAppropriateName(char.Gender, char.Culture)

char.AgeCategory = random.ItemFromThresholdMap(ageCategories)
char.AgeCategory = random.StringFromThresholdMap(ageCategories)
char.Age = getRandomAge(char.AgeCategory)

char.HairColor = random.Item(char.Culture.Appearance.HairColors)
char.HairColor = random.String(char.Culture.Appearance.HairColors)
if char.Gender == "male" {
char.HairStyle = random.Item(char.Culture.Appearance.MaleHairStyles)
char.HairStyle = random.String(char.Culture.Appearance.MaleHairStyles)
} else {
char.HairStyle = random.Item(char.Culture.Appearance.FemaleHairStyles)
char.HairStyle = random.String(char.Culture.Appearance.FemaleHairStyles)
}
char.FacialHair = char.randomFacialHair()

char.EyeColor = random.Item(char.Culture.Appearance.EyeColors)
char.EyeColor = random.String(char.Culture.Appearance.EyeColors)
char.FaceShape = char.Culture.Appearance.FaceShape
char.MouthShape = char.Culture.Appearance.MouthShape
char.NoseShape = char.Culture.Appearance.NoseShape

char.Orientation = randomOrientation()
char.Profession = random.Item(professions)
char.Profession = random.String(professions)
char.Hobby = char.getRandomHobby()
char.Motivation = random.Item(motivations)
char.Motivation = random.String(motivations)

for i := 0; i < 2; i++ {
trait := random.Item(traits)
trait := random.String(traits)
for utility.ItemInCollection(trait, char.PsychologicalTraits) {
trait = random.Item(traits)
trait = random.String(traits)
}
char.PsychologicalTraits = append(char.PsychologicalTraits, trait)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/climate/climates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package climate
import (
"math/rand"

"github.com/ironarachne/random"
"github.com/ironarachne/world/pkg/random"
)

// Climate is a climate
Expand Down Expand Up @@ -118,15 +118,15 @@ func (climate Climate) getDescription() string {
waterComponents := []string{}
if climate.HasLakes {
lakes := []string{"many smaller lakes", "a few large lakes", "an enormous lake"}
waterComponents = append(waterComponents, random.Item(lakes))
waterComponents = append(waterComponents, random.String(lakes))
}
if climate.HasRivers {
rivers := []string{"a few rivers", "a major river", "many small rivers and streams"}
waterComponents = append(waterComponents, random.Item(rivers))
waterComponents = append(waterComponents, random.String(rivers))
}
if climate.HasWetlands {
wetlands := []string{"several bogs", "extensive wetlands", "scattered wetlands"}
waterComponents = append(waterComponents, random.Item(wetlands))
waterComponents = append(waterComponents, random.String(wetlands))
}
waterComponents = shuffle(waterComponents)

Expand All @@ -138,10 +138,10 @@ func (climate Climate) getDescription() string {
if climate.HasOcean {
description += ". It lies on the coast of "
oceanTypes := []string{"a large ocean", "a gulf", "a major sea", "a smaller sea", "an ocean"}
description += random.Item(oceanTypes)
description += random.String(oceanTypes)

beachTypes := []string{"white sandy beaches", "long sandy beaches", "rocky beaches", "sheer cliffs", "low cliffs", "sandy beaches", "beautiful sandy beaches"}
description += " with " + random.Item(beachTypes)
description += " with " + random.String(beachTypes)
}

weather := ". The weather is "
Expand Down
22 changes: 11 additions & 11 deletions pkg/culture/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package culture
import (
"math/rand"

"github.com/ironarachne/random"
"github.com/ironarachne/world/pkg/random"
)

// Appearance is a set of physical characteristics
Expand Down Expand Up @@ -116,7 +116,7 @@ func (culture Culture) calculateEyeColors() []string {
}

for i := 0; i < 3; i++ {
eyeColor = random.Item(colors)
eyeColor = random.String(colors)
if !inSlice(eyeColor, eyeColors) {
eyeColors = append(eyeColors, eyeColor)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func (culture Culture) calculateHairColors() []string {
}

for i := 0; i < 2; i++ {
hairColor = random.Item(colors)
hairColor = random.String(colors)
if !inSlice(hairColor, hairColors) {
hairColors = append(hairColors, hairColor)
}
Expand All @@ -174,7 +174,7 @@ func (culture Culture) calculateHairConsistency() string {
consistencies = append(consistencies, "coarse")
}

return random.Item(consistencies)
return random.String(consistencies)
}

func (culture Culture) calculateHairStyles() []string {
Expand All @@ -200,7 +200,7 @@ func (culture Culture) calculateHairStyles() []string {
}

for i := 0; i < 3; i++ {
style = random.Item(possibleStyles)
style = random.String(possibleStyles)
if !inSlice(style, styles) {
styles = append(styles, style)
}
Expand All @@ -227,7 +227,7 @@ func randomFacialHair() []string {
}

for i := 0; i < 3; i++ {
style = random.Item(possibleStyles)
style = random.String(possibleStyles)
if !inSlice(style, styles) {
styles = append(styles, style)
}
Expand All @@ -248,7 +248,7 @@ func randomUniqueTrait() string {

chanceTrait := rand.Intn(10)
if chanceTrait > 9 {
return random.Item(possibleTraits)
return random.String(possibleTraits)
}
return "none"
}
Expand All @@ -262,7 +262,7 @@ func randomEyeShape() string {
"slanted",
}

return random.Item(shapes)
return random.String(shapes)
}

func randomFaceShape() string {
Expand All @@ -274,7 +274,7 @@ func randomFaceShape() string {
"square",
}

return random.Item(shapes)
return random.String(shapes)
}

func randomMouthShape() string {
Expand All @@ -285,7 +285,7 @@ func randomMouthShape() string {
"wide",
}

return random.Item(shapes)
return random.String(shapes)
}

func randomNoseShape() string {
Expand All @@ -298,5 +298,5 @@ func randomNoseShape() string {
"wide",
}

return random.Item(shapes)
return random.String(shapes)
}
12 changes: 6 additions & 6 deletions pkg/culture/clothing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/ironarachne/world/pkg/climate"
"github.com/ironarachne/random"
"github.com/ironarachne/world/pkg/random"
)

// ClothingItem is a type of clothing item
Expand Down Expand Up @@ -85,11 +85,11 @@ func (culture Culture) generateJewelry() []string {
numberOfJewelryPieces := rand.Intn(4) + 1

for i := 0; i < numberOfJewelryPieces; i++ {
jewelryItem = random.Item(descriptors) + " " + random.Item(materials) + " " + random.Item(foundations)
jewelryItem = random.String(descriptors) + " " + random.String(materials) + " " + random.String(foundations)
if len(gems) > 0 {
gemProbability = rand.Intn(10) + 1
if gemProbability > 5 {
jewelryItem += " " + random.Item(settings) + " " + random.Item(gems)
jewelryItem += " " + random.String(settings) + " " + random.String(gems)
}
}

Expand Down Expand Up @@ -453,7 +453,7 @@ func (culture Culture) randomDecorativeStyle() string {
styles = append(styles, "many layers")
}

return random.Item(styles)
return random.String(styles)
}

func randomColorSet() []string {
Expand All @@ -474,7 +474,7 @@ func randomColorSet() []string {
}

for i := 0; i < 3; i++ {
newColor = random.Item(colors)
newColor = random.String(colors)

if !inSlice(newColor, []string{"white", "black"}) {
saturation = randomSaturation()
Expand All @@ -499,5 +499,5 @@ func randomSaturation() string {
"subdued",
}

return random.Item(saturations)
return random.String(saturations)
}
10 changes: 5 additions & 5 deletions pkg/culture/drinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/rand"

"github.com/ironarachne/world/pkg/climate"
"github.com/ironarachne/random"
"github.com/ironarachne/world/pkg/random"
)

// Drink is an alcoholic drink
Expand Down Expand Up @@ -64,17 +64,17 @@ func (culture Culture) generateDrinks() []Drink {
if len(types) > 0 {
for i := 0; i < 2; i++ {
drink = Drink{}
drink.Base = random.Item(types)
drink.Strength = random.Item(strengths)
drink.Base = random.String(types)
drink.Strength = random.String(strengths)
numberOfIngredients = rand.Intn(4) + 1
drink.Ingredients = append(drink.Ingredients, drink.Base)
for i := 0; i < numberOfIngredients; i++ {
ingredient = random.Item(possibleIngredients)
ingredient = random.String(possibleIngredients)
if !inSlice(ingredient, drink.Ingredients) {
drink.Ingredients = append(drink.Ingredients, ingredient)
}
}
drink.Name = drink.Base + " " + random.Item(kinds)
drink.Name = drink.Base + " " + random.String(kinds)
drinks = append(drinks, drink)
}
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/culture/food.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/rand"

"github.com/ironarachne/world/pkg/climate"
"github.com/ironarachne/random"
"github.com/ironarachne/world/pkg/random"
)

// FoodStyle is a cultural food style
Expand Down Expand Up @@ -63,7 +63,7 @@ func randomCookingTechniques() []string {
}

for i := 0; i < 3; i++ {
technique = random.Item(potentialTechniques)
technique = random.String(potentialTechniques)
if !inSlice(technique, techniques) {
techniques = append(techniques, technique)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func (culture Culture) randomBread() string {
if len(grains) > 0 {
grain := grains[rand.Intn(len(grains))]

bread = random.Item(flavors) + " " + random.Item(breadTypes) + " " + grain.Name + " bread"
bread = random.String(flavors) + " " + random.String(breadTypes) + " " + grain.Name + " bread"
}

return bread
Expand Down Expand Up @@ -135,7 +135,7 @@ func (style FoodStyle) randomDishes() []string {
}

for i := 0; i < 5; i++ {
dish = random.Item(flavors) + " " + random.Item(style.CookingTechniques) + " " + random.Item(style.CommonBases) + " with " + random.Item(style.CommonSpices)
dish = random.String(flavors) + " " + random.String(style.CookingTechniques) + " " + random.String(style.CommonBases) + " with " + random.String(style.CommonSpices)

if !inSlice(dish, dishes) {
dishes = append(dishes, dish)
Expand Down Expand Up @@ -188,17 +188,17 @@ func randomEatingTraits() []string {
}

for i := 0; i < 2; i++ {
t = random.Item(potentialTraits)
t = random.String(potentialTraits)
if !inSlice(t, typesOfTraits) {
typesOfTraits = append(typesOfTraits, t)
if t == "utensils" {
trait = "eat with " + random.Item(utensils)
trait = "eat with " + random.String(utensils)
} else if t == "spices" {
trait = random.Item(spices) + " spice"
trait = random.String(spices) + " spice"
} else if t == "heat" {
trait = "food is usually " + random.Item(heat)
trait = "food is usually " + random.String(heat)
} else if t == "customs" {
trait = random.Item(customs)
trait = random.String(customs)
}
traits = append(traits, trait)
}
Expand Down
Loading

0 comments on commit e3e06a8

Please sign in to comment.