Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
585d1eb7
Commit
585d1eb7
authored
Nov 30, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support double random number generation in range [0,1).
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
9e3838ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
random.hh
src/random.hh
+18
-0
testrandom.cc
src/testrandom.cc
+2
-0
No files found.
src/random.hh
View file @
585d1eb7
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include <vector>
#include <vector>
#include <string>
#include <string>
#include <random>
class
Random
class
Random
{
{
...
@@ -41,6 +42,8 @@ private:
...
@@ -41,6 +42,8 @@ private:
std
::
vector
<
uint64_t
>
buffer
;
std
::
vector
<
uint64_t
>
buffer
;
size_t
buffer_pos
=
0
;
size_t
buffer_pos
=
0
;
std
::
uniform_real_distribution
<
double
>
double_dist
;
void
die_on_error
(
const
char
*
func
,
gcry_error_t
error
);
void
die_on_error
(
const
char
*
func
,
gcry_error_t
error
);
public
:
public
:
Random
(
uint64_t
seed
,
Stream
stream
);
Random
(
uint64_t
seed
,
Stream
stream
);
...
@@ -54,6 +57,21 @@ public:
...
@@ -54,6 +57,21 @@ public:
return
buffer
[
buffer_pos
++
];
return
buffer
[
buffer_pos
++
];
}
}
uint64_t
min
()
const
{
return
0
;
}
uint64_t
max
()
const
{
return
UINT64_MAX
;
}
double
random_double
()
/* range [0,1) */
{
return
double_dist
(
*
this
);
}
void
refill_buffer
();
void
refill_buffer
();
void
seed
(
uint64_t
seed
,
Stream
stream
);
void
seed
(
uint64_t
seed
,
Stream
stream
);
...
...
src/testrandom.cc
View file @
585d1eb7
...
@@ -30,6 +30,8 @@ main (int argc, char **argv)
...
@@ -30,6 +30,8 @@ main (int argc, char **argv)
uint64_t
x
=
rng
();
uint64_t
x
=
rng
();
printf
(
"%016lx
\n
"
,
x
);
printf
(
"%016lx
\n
"
,
x
);
}
}
for
(
size_t
i
=
0
;
i
<
20
;
i
++
)
printf
(
"%f
\n
"
,
rng
.
random_double
());
uint64_t
s
=
0
;
uint64_t
s
=
0
;
double
t_start
=
get_time
();
double
t_start
=
get_time
();
...
...
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