github.com/kongr45gpen/mattermost-server@v5.11.1+incompatible/utils/random.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"math/rand"
     8  )
     9  
    10  type Range struct {
    11  	Begin int
    12  	End   int
    13  }
    14  
    15  func RandIntFromRange(r Range) int {
    16  	if r.End-r.Begin <= 0 {
    17  		return r.Begin
    18  	}
    19  	return rand.Intn((r.End-r.Begin)+1) + r.Begin
    20  }