Skip to content

Commit

Permalink
Merge pull request #71 from awesee/dev
Browse files Browse the repository at this point in the history
U: php.Rand
  • Loading branch information
Shuo authored Dec 17, 2021
2 parents e127e5a + 85c4778 commit 5eed998
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.16

- name: Test
run: go test ./...
16 changes: 6 additions & 10 deletions php/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,14 @@ func Pow(x, y float64) float64 {
}

// Rand - Generate a random integer
func Rand(args ...int) int {
func Rand(num ...int) int {
rand.Seed(time.Now().Unix())
l := len(args)
if l > 1 {
min := math.Min(float64(args[0]), float64(args[1]))
max := math.Max(float64(args[0]), float64(args[1]))
return int(min + rand.Float64()*(max-min))
} else if l > 0 {
return rand.Intn(args[0])
} else {
return rand.Int()
if l := len(num); l == 1 && num[0] >= 1 {
return rand.Intn(num[0] + 1)
} else if l >= 2 && num[0] < num[1] {
return num[0] + rand.Intn(num[1]-num[0]+1)
}
return rand.Int()
}

// Round - Rounds a float
Expand Down

0 comments on commit 5eed998

Please sign in to comment.