This repository has been archived on 2024-02-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
astontest/adapters/randomstring/service.go

33 lines
490 B
Go

package randomstring
import (
"context"
"math/rand"
)
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
type Service struct {
chars []rune
length int
size uint
}
func New(size uint) *Service {
return &Service{
chars: []rune(chars),
length: len([]rune(chars)),
size: size,
}
}
func (s *Service) NewString(context.Context) string {
res := make([]rune, s.size)
for i := uint(0); i < s.size; i++ {
res[i] = s.chars[rand.Intn(s.length)]
}
return string(res)
}