You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
386 B
Go
24 lines
386 B
Go
8 months ago
|
package api
|
||
|
|
||
|
import (
|
||
|
"crypto/md5"
|
||
|
"encoding/binary"
|
||
|
"math"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var seedKey []byte // 32 bytes
|
||
|
|
||
|
func SetSeedKey(key []byte) {
|
||
|
seedKey = key
|
||
|
}
|
||
|
|
||
|
func SeedFromTime(seedTime time.Time) []byte {
|
||
|
day := make([]byte, 8)
|
||
|
binary.BigEndian.PutUint64(day, uint64(math.Floor(float64(seedTime.Unix())/float64(time.Hour*24))))
|
||
|
|
||
|
sum := md5.Sum(append(seedKey, day...))
|
||
|
|
||
|
return sum[:]
|
||
|
}
|