Skip to content

Commit

Permalink
misc - added float range
Browse files Browse the repository at this point in the history
  • Loading branch information
brianvoe committed Jun 2, 2017
1 parent 637dd37 commit f12e077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ func randIntRange(min, max int) int {
}
return rand.Intn((max+1)-min) + min
}

func randFloatRange(min, max float64) float64 {
if min == max {
return min
}
return rand.Float64()*(max-min) + min
}
6 changes: 6 additions & 0 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ func TestGetRandValueFail(t *testing.T) {
t.Error("You should have gotten no value back")
}
}

func TestRandFloatRangeSame(t *testing.T) {
if randFloatRange(5.0, 5.0) != 5.0 {
t.Error("You should have gotten 5.0 back")
}
}

0 comments on commit f12e077

Please sign in to comment.