improve package grand

This commit is contained in:
John Guo
2022-03-15 17:09:35 +08:00
parent 60340a7348
commit e06f831205
2 changed files with 4 additions and 8 deletions

View File

@ -6,7 +6,7 @@ require (
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.0.0-rc2
github.com/gogf/gf/v2 v2.0.0-rc
github.com/gogf/gf/v2 v2.0.0
github.com/olekukonko/tablewriter v0.0.5
)

View File

@ -60,16 +60,12 @@ func N(min, max int) int {
return min
}
if min >= 0 {
// Because Intn dose not support negative number,
// so we should first shift the value to left,
// then call Intn to produce the random number,
// and finally shift the result back to right.
return Intn(max-(min-0)+1) + (min - 0)
return Intn(max-min+1) + min
}
if min < 0 {
// Because Intn dose not support negative number,
// As `Intn` dose not support negative number,
// so we should first shift the value to right,
// then call Intn to produce the random number,
// then call `Intn` to produce the random number,
// and finally shift the result back to left.
return Intn(max+(0-min)+1) - (0 - min)
}