2020-10-30 21:20:08 +00:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/types"
|
2020-10-30 21:20:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const charset = "abcdefghijklmnopqrstuvwxyz" +
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
|
|
|
|
var seededRand *rand.Rand = rand.New(
|
|
|
|
rand.NewSource(time.Now().UnixNano()))
|
|
|
|
|
|
|
|
func StringWithCharset(length int, charset string) string {
|
|
|
|
b := make([]byte, length)
|
|
|
|
for i := range b {
|
|
|
|
b[i] = charset[seededRand.Intn(len(charset))]
|
|
|
|
}
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func String(length int) string {
|
|
|
|
return StringWithCharset(length, charset)
|
|
|
|
}
|
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
func RandomPackage() *types.Package {
|
|
|
|
return types.NewPackage(String(5), strconv.Itoa(rand.Intn(100)), []*types.Package{}, []*types.Package{})
|
2020-10-30 21:20:08 +00:00
|
|
|
}
|