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
cb22b62a
Commit
cb22b62a
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util: remove broken rand
parent
37ce1863
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
22 deletions
+15
-22
pin/pin_test.go
pin/pin_test.go
+1
-1
unixfs/io/dagmodifier_test.go
unixfs/io/dagmodifier_test.go
+4
-4
util/util.go
util/util.go
+9
-16
util/util_test.go
util/util_test.go
+1
-1
No files found.
pin/pin_test.go
View file @
cb22b62a
...
...
@@ -12,7 +12,7 @@ import (
func
randNode
()
(
*
mdag
.
Node
,
util
.
Key
)
{
nd
:=
new
(
mdag
.
Node
)
nd
.
Data
=
make
([]
byte
,
32
)
util
.
New
Fast
Rand
()
.
Read
(
nd
.
Data
)
util
.
New
TimeSeeded
Rand
()
.
Read
(
nd
.
Data
)
k
,
_
:=
nd
.
Key
()
return
nd
,
k
}
...
...
This diff is collapsed.
Click to expand it.
unixfs/io/dagmodifier_test.go
View file @
cb22b62a
...
...
@@ -28,7 +28,7 @@ func getMockDagServ(t *testing.T) mdag.DAGService {
func
getNode
(
t
*
testing
.
T
,
dserv
mdag
.
DAGService
,
size
int64
)
([]
byte
,
*
mdag
.
Node
)
{
dw
:=
NewDagWriter
(
dserv
,
&
chunk
.
SizeSplitter
{
500
})
n
,
err
:=
io
.
CopyN
(
dw
,
u
.
New
Fast
Rand
(),
size
)
n
,
err
:=
io
.
CopyN
(
dw
,
u
.
New
TimeSeeded
Rand
(),
size
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -58,7 +58,7 @@ func getNode(t *testing.T, dserv mdag.DAGService, size int64) ([]byte, *mdag.Nod
func
testModWrite
(
t
*
testing
.
T
,
beg
,
size
uint64
,
orig
[]
byte
,
dm
*
DagModifier
)
[]
byte
{
newdata
:=
make
([]
byte
,
size
)
r
:=
u
.
New
Fast
Rand
()
r
:=
u
.
New
TimeSeeded
Rand
()
r
.
Read
(
newdata
)
if
size
+
beg
>
uint64
(
len
(
orig
))
{
...
...
@@ -160,7 +160,7 @@ func TestMultiWrite(t *testing.T) {
}
data
:=
make
([]
byte
,
4000
)
u
.
New
Fast
Rand
()
.
Read
(
data
)
u
.
New
TimeSeeded
Rand
()
.
Read
(
data
)
for
i
:=
0
;
i
<
len
(
data
);
i
++
{
n
,
err
:=
dagmod
.
WriteAt
(
data
[
i
:
i
+
1
],
uint64
(
i
))
...
...
@@ -201,7 +201,7 @@ func TestMultiWriteCoal(t *testing.T) {
}
data
:=
make
([]
byte
,
4000
)
u
.
New
Fast
Rand
()
.
Read
(
data
)
u
.
New
TimeSeeded
Rand
()
.
Read
(
data
)
for
i
:=
0
;
i
<
len
(
data
);
i
++
{
n
,
err
:=
dagmod
.
WriteAt
(
data
[
:
i
+
1
],
0
)
...
...
This diff is collapsed.
Click to expand it.
util/util.go
View file @
cb22b62a
...
...
@@ -97,28 +97,21 @@ func (bcr *byteChanReader) Read(b []byte) (int, error) {
}
type
randGen
struct
{
src
rand
.
Source
rand
.
Rand
}
func
NewFastRand
()
io
.
Reader
{
return
&
randGen
{
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
())}
func
NewTimeSeededRand
()
io
.
Reader
{
src
:=
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
())
return
&
randGen
{
Rand
:
*
rand
.
New
(
src
),
}
}
func
(
r
*
randGen
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
todo
:=
len
(
p
)
offset
:=
0
for
{
val
:=
int64
(
r
.
src
.
Int63
())
for
i
:=
0
;
i
<
8
;
i
++
{
p
[
offset
]
=
byte
(
val
&
0xff
)
todo
--
if
todo
==
0
{
return
len
(
p
),
nil
}
offset
++
val
>>=
8
}
for
i
:=
0
;
i
<
len
(
p
);
i
++
{
p
[
i
]
=
byte
(
r
.
Rand
.
Intn
(
255
))
}
return
len
(
p
),
nil
}
// GetenvBool is the way to check an env var as a boolean
...
...
This diff is collapsed.
Click to expand it.
util/util_test.go
View file @
cb22b62a
...
...
@@ -31,7 +31,7 @@ func TestKey(t *testing.T) {
func
TestByteChanReader
(
t
*
testing
.
T
)
{
data
:=
make
([]
byte
,
1024
*
1024
)
r
:=
New
Fast
Rand
()
r
:=
New
TimeSeeded
Rand
()
r
.
Read
(
data
)
dch
:=
make
(
chan
[]
byte
,
8
)
...
...
This diff is collapsed.
Click to expand it.
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