Skip to content

Commit

Permalink
chore: change sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Jul 31, 2020
1 parent ceb1e77 commit b8555bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func main() {
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!

c := wr.NewChooser(
wr.Choice{Item: "🍆", Weight: 0}, // alternatively: wr.NewChoice('🍆', 0)
wr.Choice{Item: "🍒", Weight: 0}, // alternatively: wr.NewChoice('🍒', 0)
wr.Choice{Item: "🍋", Weight: 1},
wr.Choice{Item: "🍊", Weight: 1},
wr.Choice{Item: "🍉", Weight: 3},
wr.Choice{Item: "🥑", Weight: 5},
)
/* The following will print 🍋 and 🍊 with 0.1 probability, 🍉 with 0.3
probability, and 🥑 with 0.5 probability. 🍆 will never be printed. (Note
probability, and 🥑 with 0.5 probability. 🍒 will never be printed. (Note
the weights don't have to add up to 10, that was just done here to make the
example easier to read.) */
result := c.Pick().(string)
Expand Down
8 changes: 4 additions & 4 deletions examples/frequency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
rand.Seed(time.Now().UTC().UnixNano()) // always seed random!

c := wr.NewChooser(
wr.Choice{Item: '🍆', Weight: 0}, // alternatively: wr.NewChoice('🍆', 0)
wr.Choice{Item: '🍒', Weight: 0}, // alternatively: wr.NewChoice('🍒', 0)
wr.Choice{Item: '🍋', Weight: 1},
wr.Choice{Item: '🍊', Weight: 1},
wr.Choice{Item: '🍉', Weight: 3},
Expand All @@ -27,13 +27,13 @@ func main() {
fmt.Println(string(fruits))

/* That should have printed 🍋 and 🍊 with 0.1 probability, 🍉 with 0.3
probability, and 🥑 with 0.5 probability. 🍆 should never be printed. (Note
probability, and 🥑 with 0.5 probability. 🍒 should never be printed. (Note
the weights don't have to add up to 10, that was just done here to make the
example easier to read.) */
freqs := make(map[rune]int)
for _, f := range fruits {
freqs[f]++
}
fmt.Printf("\n🍆: %d\t🍋: %d\t🍊: %d\t🍉: %d\t🥑: %d\n",
freqs['🍆'], freqs['🍋'], freqs['🍊'], freqs['🍉'], freqs['🥑'])
fmt.Printf("\n🍒: %d\t🍋: %d\t🍊: %d\t🍉: %d\t🥑: %d\n",
freqs['🍒'], freqs['🍋'], freqs['🍊'], freqs['🍉'], freqs['🥑'])
}

0 comments on commit b8555bc

Please sign in to comment.