Skip to content

Commit 587c245

Browse files
committed
updated randomword function
1 parent b7caf06 commit 587c245

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

randomword.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@ package randomtext
22

33
import (
44
"errors"
5+
"math/rand"
56
"strings"
67
)
7-
8+
func getRandomNumber() int {
9+
return rand.Intn(3)+1
10+
}
811
func RandomWord(length uint, separator string) (string, error) {
912
if length == 0 {
1013
return "", errors.New("length cannot be 0")
1114
}
1215

1316
var words []string
1417
for i := 0; i < int(length); i++ {
15-
if i%2 == 0 {
18+
randomIndex := getRandomNumber();
19+
if randomIndex == 1 {
1620
words = append(words, Noun())
17-
} else {
21+
} else if randomIndex == 2{
1822
words = append(words, Adjective())
23+
} else {
24+
words = append(words, Animal())
1925
}
2026
}
2127

0 commit comments

Comments
 (0)