Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
0a097b5c
Commit
0a097b5c
authored
Sep 12, 2008
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change rand names to match type names
R=r DELTA=66 (19 added, 9 deleted, 38 changed) OCL=15232 CL=15265
parent
729bc5c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
34 deletions
+44
-34
src/lib/rand.go
src/lib/rand.go
+44
-34
No files found.
src/lib/rand.go
View file @
0a097b5c
...
@@ -9,17 +9,11 @@
...
@@ -9,17 +9,11 @@
*/
*/
package
rand
package
rand
/*
export
// rand, rand31, rand63 - return non-negative random int, int32, int64
srand // set rand state (int32)
// urand32 - return random uint32
vrand // int64 63-bits
// nrand, nrand31, nrand63 - return 0 <= random < n
lrand // int32 31-bits
// frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1
rand // int 15-bits
vnrand // int64 % (int64)
lnrand // int32 % (int32)
nrand // int % (int)
frand; // float64 >=0.0 <1.0
*/
const
const
(
(
...
@@ -84,7 +78,7 @@ srand(seed int32)
...
@@ -84,7 +78,7 @@ srand(seed int32)
}
}
export
func
export
func
vrand
()
int64
rand63
()
int64
{
{
rng_tap
--
;
rng_tap
--
;
if
rng_tap
<
0
{
if
rng_tap
<
0
{
...
@@ -102,56 +96,72 @@ vrand() int64
...
@@ -102,56 +96,72 @@ vrand() int64
}
}
export
func
export
func
lrand
()
int32
urand32
()
u
int32
{
{
x
:=
vrand
()
&
0x7fffffff
;
return
uint32
(
rand63
()
>>
31
);
return
int32
(
x
);
}
}
export
func
export
func
rand
()
int
rand
31
()
int32
{
{
x
:=
vrand
()
&
0x7fff
;
return
int32
(
rand63
()
>>
32
);
return
int
(
x
);
}
}
export
func
export
func
vnrand
(
n
int64
)
int64
rand
()
int
{
{
var
v
,
slop
int64
;
u
:=
uint
(
rand63
());
return
int
(
u
<<
1
>>
1
);
// clear sign bit if int == int32
}
slop
=
MASK
%
n
;
export
func
for
v
=
vrand
();
v
<=
slop
;
v
=
vrand
()
{
nrand63
(
n
int64
)
int64
{
if
n
<=
0
{
return
0
}
}
return
v
%
n
;
max
:=
int64
((
1
<<
63
)
-
1
-
(
1
<<
63
)
%
uint64
(
n
));
v
:=
rand63
()
for
v
>
max
{
v
=
rand63
()
}
return
v
%
n
}
}
export
func
export
func
lnrand
(
n
int32
)
int32
nrand31
(
n
int32
)
int32
{
{
v
:=
vnrand
(
int64
(
n
));
return
int32
(
nrand63
(
int64
(
n
)))
return
int32
(
v
);
}
}
export
func
export
func
nrand
(
n
int
)
int
nrand
(
n
int
)
int
{
{
v
:=
vnrand
(
int64
(
n
));
return
int
(
nrand63
(
int64
(
n
)))
return
int
(
v
);
}
}
export
func
export
func
frand
()
float64
frand
64
()
float64
{
{
var
x
float64
;
x
:=
float64
(
rand63
())
/
float64
(
MASK
);
x
=
float64
(
vrand
())
/
float64
(
MASK
);
for
x
>=
1
{
for
x
>=
1
{
x
=
float64
(
vrand
())
/
float64
(
MASK
);
x
=
float64
(
rand63
())
/
float64
(
MASK
);
}
}
return
x
;
return
x
;
}
}
export
func
frand32
()
float32
{
return
float32
(
frand64
())
}
export
func
frand
()
float
{
return
float
(
frand64
())
}
func
func
init
()
init
()
{
{
...
...
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