Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OptLP
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
PMC-SOG
OptLP
Commits
5ae13801
Commit
5ae13801
authored
4 months ago
by
Jaime Arias
Browse files
Options
Downloads
Patches
Plain Diff
refactor: create a random function
parent
7f2da6b6
No related branches found
No related tags found
No related merge requests found
Pipeline
#8734
passed with stages
Stage:
Stage:
in 8 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.clang-tidy
+1
-1
1 addition, 1 deletion
.clang-tidy
src/graph.cpp
+13
-5
13 additions, 5 deletions
src/graph.cpp
with
14 additions
and
6 deletions
.clang-tidy
+
1
−
1
View file @
5ae13801
Checks: 'cppcoreguidelines-*,google-*,modernize-use-nullptr,performance-*,portability-*,readability-*'
Checks: 'cppcoreguidelines-*,google-*,modernize-use-nullptr,performance-*,portability-*,readability-*
,-cppcoreguidelines-owning-memory
'
WarningsAsErrors: true
FormatStyle: google
This diff is collapsed.
Click to expand it.
src/graph.cpp
+
13
−
5
View file @
5ae13801
...
...
@@ -12,6 +12,15 @@
using
namespace
std
;
/**
* Generate a random number between 0 and max
* @param max - the maximum value
* @return the random number
*/
int
random
(
int
max
)
{
return
static_cast
<
int
>
(
arc4random
()
%
max
);
}
/**
* Generate a random string of a given length
* @param length - the length of the string
...
...
@@ -26,7 +35,7 @@ string RandomString(int length) {
'n'
,
'o'
,
'p'
,
'q'
,
'r'
,
's'
,
't'
,
'u'
,
'v'
,
'w'
,
'x'
,
'y'
,
'z'
};
for
(
int
i
=
0
;
i
<
length
;
++
i
)
{
result
+=
alphabet
.
at
(
rand
()
%
alphabet_size
);
result
+=
alphabet
.
at
(
rand
om
(
alphabet_size
)
)
;
}
return
result
;
...
...
@@ -57,7 +66,7 @@ std::vector<std::string> split(const std::string &str, char delimiter) {
*/
template
<
typename
T
>
T
GetRandomElement
(
const
std
::
set
<
T
>
&
elements
)
{
return
*
std
::
next
(
elements
.
begin
(),
rand
()
%
elements
.
size
());
return
*
std
::
next
(
elements
.
begin
(),
rand
om
(
elements
.
size
())
)
;
}
Graph
::
Graph
(){};
...
...
@@ -173,7 +182,6 @@ Graph::Graph(const string &filename) {
Graph
*
Graph
::
GenerateRandomGraph
(
int
n_states
,
int
n_transitions
,
int
n_labels
)
{
srand
(
time
(
nullptr
));
// seed the random number generator
Graph
*
graph
=
new
Graph
();
// create states
...
...
@@ -236,7 +244,7 @@ Graph *Graph::GenerateRandomGraph(int n_states, int n_transitions,
// add additional transitions randomly
while
(
counter_transitions
<
n_transitions
)
{
// choose a random source node
int
source_id
=
rand
()
%
n_states
;
int
source_id
=
rand
om
(
n_states
)
;
Node
*
source
=
graph
->
get_state
(
source_id
);
// Ensure the chosen transition label is unique for the current node
...
...
@@ -249,7 +257,7 @@ Graph *Graph::GenerateRandomGraph(int n_states, int n_transitions,
used_labels
[
source
].
insert
(
label
);
// Choose a random target node
int
target_id
=
rand
()
%
n_states
;
int
target_id
=
rand
om
(
n_states
)
;
// Add the transition
graph
->
add_successor
(
source_id
,
target_id
,
label
);
...
...
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