mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-19 13:44:53 +01:00
20 lines
350 B
Go
20 lines
350 B
Go
package service
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
)
|
|
|
|
func randBytesFromStr(length int, from string) ([]byte, error) {
|
|
b := make([]byte, length)
|
|
fromLenBigInt := big.NewInt(int64(len(from)))
|
|
for i := range b {
|
|
r, err := rand.Int(rand.Reader, fromLenBigInt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
b[i] = from[r.Int64()]
|
|
}
|
|
return b, nil
|
|
}
|