方法一
package main import ( "math/rand" "fmt" ) func main(){ for i := 0; i < 20; i++ { num:=RandInt64(1500,2000) fmt.Println(num) } } func RandInt64(min,max int64) int64 { if min >= max || min==0 || max==0{ return max } return rand.Int63n(max-min)+min }
package main import ( "math/rand" "fmt" ) func main(){ for i := 0; i < 20; i++ { num:=RandInt64(1500,max int64) int64{ if min>=max || min==0 || max==0{ return max } HUIQU: num:=rand.Int63n(max) if num<min{ goto HUIQU } return num }