Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
39605372
Commit
39605372
authored
3 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
std: add event support in the include random
parent
d5d40b19
No related branches found
Branches containing commit
No related tags found
1 merge request
!220
Merge jt
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2std/src/extensions/random.cpp
+2
-2
2 additions, 2 deletions
alib2std/src/extensions/random.cpp
alib2std/src/extensions/random.hpp
+32
-1
32 additions, 1 deletion
alib2std/src/extensions/random.hpp
with
34 additions
and
3 deletions
alib2std/src/extensions/random.cpp
+
2
−
2
View file @
39605372
...
...
@@ -2,7 +2,7 @@
namespace
ext
{
std
::
random_device
&
random_devices
::
random
=
getRandom
(
);
random_devices
::
semirandom_device
&
random_devices
::
semirandom
=
getSemirandom
(
);
std
::
random_device
&
random_devices
::
random
=
getRandom
(
);
random_devices
::
semirandom_device
&
random_devices
::
semirandom
=
getSemirandom
(
);
}
/* namespace ext */
This diff is collapsed.
Click to expand it.
alib2std/src/extensions/random.hpp
+
32
−
1
View file @
39605372
...
...
@@ -143,5 +143,36 @@ public:
};
}
/* namespace ext */
class
uniform_unsigned_event
{
unsigned
m_probability
;
static
constexpr
unsigned
PROBABILITY_MIN
=
0
;
static
constexpr
unsigned
PROBABILITY_MAX
=
100
;
public:
uniform_unsigned_event
(
unsigned
probability
)
:
m_probability
(
probability
)
{
}
template
<
class
Generator
>
bool
operator
(
)
(
Generator
&
g
)
const
{
static
std
::
uniform_int_distribution
<
unsigned
>
generator
(
PROBABILITY_MIN
,
PROBABILITY_MAX
-
1
);
return
generator
(
g
)
<
m_probability
;
}
};
class
uniform_real_event
{
double
m_probability
;
static
constexpr
double
PROBABILITY_MIN
=
0.
;
static
constexpr
double
PROBABILITY_MAX
=
1.
;
public:
uniform_real_event
(
double
probability
)
:
m_probability
(
probability
)
{
}
template
<
class
Generator
>
bool
operator
(
)
(
Generator
&
g
)
const
{
static
std
::
uniform_real_distribution
<
double
>
generator
(
PROBABILITY_MIN
,
PROBABILITY_MAX
);
return
generator
(
g
)
<
m_probability
;
}
};
}
/* namespace ext */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment