mirror of
https://github.com/oarkflow/mq.git
synced 2025-09-27 20:32:15 +08:00
feat: implement websocket and UI
This commit is contained in:
28
sio/rng.go
Normal file
28
sio/rng.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package sio
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RNG is a random number generator that is safe for concurrent use by multiple go routines
|
||||
type RNG struct {
|
||||
r *rand.Rand
|
||||
mu *sync.Mutex
|
||||
}
|
||||
|
||||
// Read reads len(b) random bytes into b and always returns a nil error
|
||||
func (r *RNG) Read(b []byte) (int, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.r.Read(b)
|
||||
}
|
||||
|
||||
// NewRNG creates a new random number generator
|
||||
func NewRNG() *RNG {
|
||||
return &RNG{
|
||||
r: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
mu: &sync.Mutex{},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user