Skip to content

Commit 6137454

Browse files
Float randomizer always printed zero, this is is now fixed with a new random calculation
1 parent 0fa8255 commit 6137454

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Get the program name and version
44
MOCKERFILE="mock.go"
5-
PROGRAMNAME=`grep "programName " ${MOCKERFILE} | cut -d'=' -f2|sed 's/"//g'`
6-
PROGRAMVERSION=`grep "programVersion" ${MOCKERFILE} | cut -d'=' -f2|sed 's/"//g'|sed -e 's/^[[:space:]]*//'`
5+
PROGRAMNAME=`grep "programName " ${MOCKERFILE} | cut -d'=' -f2 | sed 's/"//g' | sed -e 's/^[[:space:]]*//'`
6+
PROGRAMVERSION=`grep "programVersion" ${MOCKERFILE} | cut -d'=' -f2 | sed 's/"//g' | sed -e 's/^[[:space:]]*//'`
77
PLATFORM=("windows/amd64" "darwin/amd64" "linux/amd64")
88

99
# Loop through the platform and build a package

mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
var (
99
programName = "mock"
10-
programVersion = "v2.0"
10+
programVersion = "v2.1"
1111
ExecutionTimestamp = TimeNow()
1212
Path = fmt.Sprintf("%s/%s/%s", os.Getenv("HOME"), programName, ExecutionTimestamp)
1313
)

randomizer.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ func RandomBytea(maxlen int) []byte {
4646
}
4747

4848
// Random Float generator based on precision specified
49-
func round(num float64) int {
50-
return int(num + math.Copysign(0.5, num))
51-
}
52-
5349
func RandomFloat(min, max, precision int) (float64) {
5450
output := math.Pow(10, float64(precision))
55-
randNumber := RandomInt(min, max)
56-
return math.Floor(float64(float64(randNumber)/rand.Float64()) / output)
51+
randNumber := float64(min) + r.Float64() * float64(max - min) * 100
52+
return math.Round(randNumber) / output
5753
}
5854

5955
// Random calender date time generator

0 commit comments

Comments
 (0)