Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
cc7a869e
Commit
cc7a869e
authored
Dec 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
threadsafe SeededRand
parent
6e9cb06b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
util/testutil/rand.go
util/testutil/rand.go
+36
-0
No files found.
util/testutil/rand.go
0 → 100644
View file @
cc7a869e
package
testutil
import
(
"math/rand"
"sync"
"time"
)
var
SeededRand
*
rand
.
Rand
func
init
()
{
SeededRand
=
NewSeededRand
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
}
func
NewSeededRand
(
seed
int64
)
*
rand
.
Rand
{
src
:=
rand
.
NewSource
(
seed
)
return
rand
.
New
(
&
LockedRandSource
{
src
:
src
})
}
type
LockedRandSource
struct
{
lk
sync
.
Mutex
src
rand
.
Source
}
func
(
r
*
LockedRandSource
)
Int63
()
(
n
int64
)
{
r
.
lk
.
Lock
()
n
=
r
.
src
.
Int63
()
r
.
lk
.
Unlock
()
return
}
func
(
r
*
LockedRandSource
)
Seed
(
seed
int64
)
{
r
.
lk
.
Lock
()
r
.
src
.
Seed
(
seed
)
r
.
lk
.
Unlock
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment