Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RogueReborn
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
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
Mikhail Andrenkov
RogueReborn
Commits
f422525c
Commit
f422525c
authored
8 years ago
by
Ian Prins
Browse files
Options
Downloads
Patches
Plain Diff
add randPosition method to generator
parent
4100f91f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/random.h
+2
-0
2 additions, 0 deletions
src/include/random.h
src/random.cpp
+5
-0
5 additions, 0 deletions
src/random.cpp
with
7 additions
and
0 deletions
src/include/random.h
+
2
−
0
View file @
f422525c
#include
<random>
#include
"coord.h"
#ifndef RANDOM_H
#define RANDOM_H
...
...
@@ -8,6 +9,7 @@ class Generator {
Generator
();
int
intFromRange
(
int
,
int
);
double
operator
()();
Coord
randPosition
(
Coord
,
Coord
);
private:
std
::
mt19937
gen
;
};
...
...
This diff is collapsed.
Click to expand it.
src/random.cpp
+
5
−
0
View file @
f422525c
#include
<random>
#include
"include/random.h"
#include
"include/coord.h"
Generator
::
Generator
()
{
gen
=
std
::
mt19937
(
std
::
random_device
()());
...
...
@@ -13,3 +14,7 @@ int Generator::intFromRange(int lower, int upper) {
double
Generator
::
operator
()()
{
return
std
::
uniform_real_distribution
<>
(
0
,
1
)(
gen
);
}
Coord
Generator
::
randPosition
(
Coord
a
,
Coord
b
)
{
return
Coord
(
intFromRange
(
a
[
0
],
b
[
0
]),
intFromRange
(
a
[
1
],
b
[
1
]));
}
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