master
Charles Iliya Krempeaux 2022-12-14 06:12:31 -08:00
parent 728a1b8a01
commit 3fc35d7a32
2 changed files with 91 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package arbitrary
import (
"math/rand"
"net"
"time"
)
@ -14,6 +15,11 @@ func Bool() bool {
return Default.Bool()
}
// NetAddr returns an arbitrary net.Addr.
func NetAddr() net.Addr {
return Default.NetAddr()
}
// Password returns an arbitrary password.
func Password() string {
return Default.Password()

85
t_netaddr.go 100644
View File

@ -0,0 +1,85 @@
package arbitrary
import (
"fmt"
"net"
)
// NetAddr returns an arbitrary net.Addr.
func (arb T) NetAddr() net.Addr {
var network string
{
if arb.Bool() {
network = "tcp"
} else {
network = "udp"
}
}
var port uint16
{
port = uint16(arb.randomness.Intn(65536))
if 0 == arb.randomness.Intn(5) {
port = uint16(arb.randomness.Intn(1024))
}
if 0 == arb.randomness.Intn(4) {
port = uint16(arb.randomness.Intn(100))
}
if 0 == arb.randomness.Intn(30) {
port = 80
}
if 0 == arb.randomness.Intn(40) {
port = 79
}
}
var value string
func(){
value = fmt.Sprintf("%d.%d.%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(256), port)
if 0 == arb.randomness.Intn(16) {
value = fmt.Sprintf("127.0.0.1:%d", port)
return
}
if 0 == arb.randomness.Intn(16) {
value = fmt.Sprintf("192.168.0.1:%d", port)
return
}
if 0 == arb.randomness.Intn(7) {
value = fmt.Sprintf("%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(16777216), port)
return
}
if 0 == arb.randomness.Intn(7) {
value = fmt.Sprintf("%d.%d.%d:%d", arb.randomness.Intn(256), arb.randomness.Intn(256), arb.randomness.Intn(65536), port)
return
}
}()
return internalNetAddr{
network: network,
value: value,
}
}
type internalNetAddr struct {
network string
value string
}
var _ net.Addr = internalNetAddr{}
func (receiver internalNetAddr) Network() string {
return receiver.network
}
func (receiver internalNetAddr) String() string {
return receiver.value
}