mirror of
https://github.com/go-i2p/go-sam-go.git
synced 2025-07-25 08:29:03 -04:00
work on new constructors
This commit is contained in:
@@ -37,11 +37,12 @@ func SplitHostPort(hostport string) (string, string, error) {
|
||||
return host, port, nil
|
||||
}
|
||||
|
||||
var randSource = rand.NewSource(time.Now().UnixNano())
|
||||
var randGen = rand.New(randSource)
|
||||
|
||||
func RandPort() string {
|
||||
for {
|
||||
s := rand.NewSource(time.Now().UnixNano())
|
||||
r := rand.New(s)
|
||||
p := r.Intn(55534) + 10000
|
||||
p := randGen.Intn(55534) + 10000
|
||||
port := strconv.Itoa(p)
|
||||
if l, e := net.Listen("tcp", net.JoinHostPort("localhost", port)); e != nil {
|
||||
continue
|
||||
@@ -54,6 +55,5 @@ func RandPort() string {
|
||||
return strconv.Itoa(l.Addr().(*net.UDPAddr).Port)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user