File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 88 "regexp"
99 "strconv"
1010 "strings"
11+ "os"
12+ "bufio"
1113 "time"
1214 "github.com/c-robinson/iplib"
1315)
@@ -149,6 +151,15 @@ func ShuffleSlice(s []string) []string {
149151 return s
150152}
151153
154+ // ShuffleSliceInt randomly shuffles a list of integers.
155+ func ShuffleSliceInt (s []int ) []int {
156+ rand .Seed (time .Now ().UnixNano ())
157+ rand .Shuffle (len (s ), func (i , j int ) {
158+ s [i ], s [j ] = s [j ], s [i ]
159+ })
160+ return s
161+ }
162+
152163// IpIncrement increments an IP address by 1.
153164func IpIncrement (ip net.IP ) {
154165 for j := len (ip ) - 1 ; j >= 0 ; j -- {
@@ -228,6 +239,18 @@ func Interval2Seconds(interval string) int {
228239 return i
229240}
230241
242+ // File2Slice reads a textfile and returns all lines as an array.
243+ func File2Slice (file string ) []string {
244+ fil , _ := os .Open (file )
245+ defer fil .Close ()
246+ var lines []string
247+ scanner := bufio .NewScanner (fil )
248+ for scanner .Scan () {
249+ lines = append (lines , scanner .Text ())
250+ }
251+ return lines
252+ }
253+
231254// RemoveNewLines removes possible newlines from a string.
232255func RemoveNewlines (s string ) string {
233256 re := regexp .MustCompile (`\r?\n` )
You can’t perform that action at this time.
0 commit comments