mirror of
https://github.com/lus/pasty.git
synced 2023-08-10 21:13:09 +03:00
Seed random generator
This commit is contained in:
parent
5585a26ab0
commit
7d0c25fb2f
@ -1,12 +1,16 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "math/rand"
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// stringContents holds the chars a random string can contain
|
// stringContents holds the chars a random string can contain
|
||||||
const stringContents = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
const stringContents = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
|
||||||
// RandomString returns a random string with the given length
|
// RandomString returns a random string with the given length
|
||||||
func RandomString(length int) string {
|
func RandomString(length int) string {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
bytes := make([]byte, length)
|
bytes := make([]byte, length)
|
||||||
for i := range bytes {
|
for i := range bytes {
|
||||||
bytes[i] = stringContents[rand.Int63()%int64(len(stringContents))]
|
bytes[i] = stringContents[rand.Int63()%int64(len(stringContents))]
|
||||||
|
Loading…
Reference in New Issue
Block a user