Skip to content

Commit

Permalink
add new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviaBahr committed Sep 19, 2024
1 parent 4dd10ed commit 526dba6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/template/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (

func random(list interface{}) (string, error) {
v := reflect.ValueOf(list)

if v.Kind() != reflect.Slice && v.Kind() != reflect.Array {
return "", errors.New("input must be a slice or array")
}

if v.Len() == 0 {
return "", errors.New("input slice or array is empty")
}

return fmt.Sprintf("%v", v.Index(rand.Intn(v.Len()))), nil
}

0 comments on commit 526dba6

Please sign in to comment.