From f58be2f83d8926d2cca04bede7d484cc067e0ca0 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 14 Dec 2022 06:36:14 -0800 Subject: [PATCH] network port --- default.go | 5 +++++ t_netport.go | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 t_netport.go diff --git a/default.go b/default.go index c12f4ff..9dd8493 100644 --- a/default.go +++ b/default.go @@ -26,6 +26,11 @@ func NetAddr() net.Addr { return Default.NetAddr() } +// NetPort returns an arbitrary network port. +func NetPort() uint16 { + return Default.NetPort() +} + // Password returns an arbitrary password. func Password() string { return Default.Password() diff --git a/t_netport.go b/t_netport.go new file mode 100644 index 0000000..ed29f39 --- /dev/null +++ b/t_netport.go @@ -0,0 +1,27 @@ +package arbitrary + +// NetPort returns an arbitrary network port. +func (arb T) NetPort() uint16 { + + 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(29) { + port = 79 + } + } + + return port +}