diff --git a/entropy/entropy.go b/entropy/entropy.go index 3d23a33..e5a62aa 100644 --- a/entropy/entropy.go +++ b/entropy/entropy.go @@ -23,14 +23,6 @@ func RandomStrChoice(choice []string) string { return "" } -// GetRandomSliceValue returns a random item from an input slice of strings. -func GetRandomSliceValue(choice ...any) any { - if len(choice) > 0 { - return choice[RNGUint32()%uint32(len(choice))] - } - return nil -} - // GetCryptoSeed returns a random int64 derived from crypto/rand. // This can be used as a seed for the math/rand package. func GetCryptoSeed() int64 { diff --git a/entropy/entropy_test.go b/entropy/entropy_test.go index 6d87efc..e09b2e3 100644 --- a/entropy/entropy_test.go +++ b/entropy/entropy_test.go @@ -84,27 +84,15 @@ func Test_RandStr_Entropy(t *testing.T) { t.Logf("[ENTROPY] final score (lower is better): %d (RandStr)", totalScore) } -func sliceTest[T comparable](t *testing.T, do func(...T) T) { - var slice []T - for n := 0; n != 500; n++ { - var item interface{} = RandStr(555) - slice = append(slice, item) - } - check(do(slice), do(slice), t) -} - -func Test_RandomSliceValue(t *testing.T) { +func Test_RandomStrChoice(t *testing.T) { if RandomStrChoice([]string{}) != "" { t.Fatalf("RandomStrChoice returned a value when given an empty slice") } - sliceTest(t, GetRandomSliceValue) -} - -func Test_RandomStrChoice(t *testing.T) { - if GetRandomSliceValue([]interface{}{}) != nil { - t.Fatalf("GetRandomSliceValue returned a value when given an empty slice") + var slice []string + for n := 0; n != 500; n++ { + slice = append(slice, RandStr(555)) } - sliceTest(t, RandomStrChoice) + check(RandomStrChoice(slice), RandomStrChoice(slice), t) } func Test_RNGUint32(t *testing.T) { diff --git a/network/range.go b/network/range.go index 0820b1c..5b9ecc5 100644 --- a/network/range.go +++ b/network/range.go @@ -11,9 +11,11 @@ IterateNetRange will ingest: - or a string to be parsed as either of the above options - - examples: (192.168.69.0/24) (192.168.69.0-192.168.69.254) + - valid subnet string example: 192.168.69.0/24 - then it returns a channel that will stream all the individual netaddr.IP types within the given range or prefix. + - valid range string example: 192.168.69.0-192.168.69.254 + + it then returns a channel that will stream all the individual netaddr.IP types within the given range or prefix. if the input is invalid this function will return nil. */ func IterateNetRange(ips interface{}) chan ipa.IP { @@ -39,13 +41,14 @@ func IterateNetRange(ips interface{}) chan ipa.IP { return nil } - ch := make(chan ipa.IP) + ch := make(chan ipa.IP, 254) go func(ret chan ipa.IP) { for head := addrs.From(); head != addrs.To(); head = head.Next() { if !head.IsUnspecified() { ret <- head } } + close(ret) }(ch) return ch }