Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pdptw-main
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JACQ-BODET Awen
pdptw-main
Compare revisions
2fc0df0b66309314534d1f92e2146ea34b59f8e2 to dd723af1db1e7952a1f239df26665fd03d758a1d
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
a24jacqb/pdptw-main
Select target project
No results found
dd723af1db1e7952a1f239df26665fd03d758a1d
Select Git revision
Branches
main
1 result
Swap
Target
a24jacqb/pdptw-main
Select target project
a24jacqb/pdptw-main
1 result
2fc0df0b66309314534d1f92e2146ea34b59f8e2
Select Git revision
Branches
main
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils.cpp
+42
-0
42 additions, 0 deletions
src/utils.cpp
src/utils.h
+27
-0
27 additions, 0 deletions
src/utils.h
with
69 additions
and
0 deletions
src/utils.cpp
0 → 100644
View file @
dd723af1
#include
"utils.h"
#include
"config.h"
#include
<random>
namespace
// anonymous namespace
{
std
::
mt19937_64
randomGenerator
;
// NOLINT(*-msc51-cpp) => deterministic random!
bool
seedSet
=
false
;
std
::
uniform_real_distribution
<>
distribution
(
0
,
1
);
}
// namespace
double
util
::
getRandom
()
{
if
(
!
seedSet
)
[[
unlikely
]]
{
randomGenerator
.
seed
(
RANDOM_SEED
);
seedSet
=
true
;
}
return
distribution
(
randomGenerator
);
}
unsigned
int
util
::
getRandomInt
(
unsigned
int
min
,
unsigned
int
max
)
{
if
(
!
seedSet
)
[[
unlikely
]]
{
randomGenerator
.
seed
(
RANDOM_SEED
);
seedSet
=
true
;
}
return
std
::
uniform_int_distribution
<>
(
min
,
max
)(
randomGenerator
);
}
std
::
mt19937_64
&
util
::
getRawRandom
()
{
if
(
!
seedSet
)
[[
unlikely
]]
{
randomGenerator
.
seed
(
RANDOM_SEED
);
seedSet
=
true
;
}
return
randomGenerator
;
}
This diff is collapsed.
Click to expand it.
src/utils.h
0 → 100644
View file @
dd723af1
#pragma once
#include
<algorithm>
#include
<functional>
#include
<memory>
#include
<random>
#include
<stdexcept>
#include
<string>
#include
<vector>
namespace
util
{
/**
* Get a random number
* @return a number between 0 (inclusive) and 1 (exclusive)
*/
double
getRandom
();
/**
* @return a random integer number between min (included) and max (included)
*/
unsigned
int
getRandomInt
(
unsigned
int
min
,
unsigned
int
max
);
/**
* @return the random generator directly, it is a deterministic random
*/
std
::
mt19937_64
&
getRawRandom
();
}
// namespace util
This diff is collapsed.
Click to expand it.
Prev
1
2
3
Next