Skip to content

Commit

Permalink
[rand] Remove method 'Int' + Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Aug 11, 2024
1 parent 3cbc99b commit 51b5425
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### [13.3.2](https://kaos.sh/ek/13.3.2)

- `[support/apps]` Added support for Docker, Podman, and LXC
- `[rand]` Removed method `Int`
- `[rand]` Code refactoring

### [13.3.1](https://kaos.sh/ek/13.3.1)

Expand Down
14 changes: 4 additions & 10 deletions rand/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,29 @@ func String(length int) string {
return ""
}

rnd := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
symbolsLength := len(symbols)
result := make([]byte, length)

rand.Seed(time.Now().UTC().UnixNano())

for i := 0; i < length; i++ {
result[i] = symbols[rand.Intn(symbolsLength)]
result[i] = symbols[rnd.Intn(symbolsLength)]
}

return string(result)
}

// Int returns random int
func Int(n int) int {
rand.Seed(time.Now().UTC().UnixNano())
return rand.Intn(n)
}

// Slice returns slice with random chars
func Slice(length int) []string {
if length == 0 {
return []string{}
}

rnd := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
symbolsLength := len(symbols)
result := make([]string, length)

for i := 0; i < length; i++ {
result[i] = string(symbols[rand.Intn(symbolsLength)])
result[i] = string(symbols[rnd.Intn(symbolsLength)])
}

return result
Expand Down
11 changes: 0 additions & 11 deletions rand/rand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ func (s *RandSuite) TestString(c *C) {
c.Assert(len(String(-100)), Equals, 0)
}

func (s *RandSuite) TestInt(c *C) {
n := 1000
k := 0

for i := 0; i < 1000; i++ {
k += Int(n)
}

c.Assert(k/n, Not(Equals), n)
}

func (s *RandSuite) TestSlice(c *C) {
t1 := strings.Join(Slice(256), "")
t2 := strings.Join(Slice(256), "")
Expand Down

0 comments on commit 51b5425

Please sign in to comment.