Skip to content

Commit

Permalink
Fixing some issues in uniform_random; Adding range test to uniform_ra…
Browse files Browse the repository at this point in the history
…ndom.
  • Loading branch information
mdavis36 committed Aug 5, 2021
1 parent 1d39a9b commit 57b7c8f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Pybind11Wraps/Utilities/uniform_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def pyinit(self):

def pyinit1(self,
seed = "const size_t",
minVal = "const double",
maxVal = "const double"):
minVal = ("const double", "0.0"),
maxVal = ("const double", "1.0")):
"Construct with a seed value and range"

def pyinit2(self, rhs="const uniform_random&"):
Expand Down
9 changes: 7 additions & 2 deletions src/Utilities/tests/test_uniform_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def testComparisons(self):
gen1 = uniform_random(seed)
gen2 = uniform_random(seed + 1)
assert gen1 != gen2
gen2.seed(seed)
gen2.seed = seed
assert gen1 == gen2
gen3 = uniform_random(seed, 2.0, 3.0)
assert gen3 != gen1
Expand All @@ -76,7 +76,12 @@ def testAdvance(self):
#===========================================================================
def testRange(self):
seed = rangen.randint(1, 2**64)
xmin = rangen.
gen1 = uniform_random(seed)
assert gen1.min == 0.0
assert gen1.max == 1.0
gen1.range(5.0, 10.0)
assert gen1.min == 5.0
assert gen1.max == 10.0

#===========================================================================
# Serialization
Expand Down
4 changes: 3 additions & 1 deletion src/Utilities/uniform_random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ uniform_random::seed(const size_t val) {
//------------------------------------------------------------------------------
void
uniform_random::range(const double a, const double b) {
mRan = std::uniform_real_distribution<double>(a, b);
mMin = a;
mMax = b;
mRan = std::uniform_real_distribution<double>(mMin, mMax);
}

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/uniform_random_Inline.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ uniform_random::operator==(const uniform_random& rhs) const {
inline
bool
uniform_random::operator!=(const uniform_random& rhs) const {
return (mGen != rhs.mGen) || (mRan == rhs.mRan);
return (mGen != rhs.mGen) || (mRan != rhs.mRan);
}

}

0 comments on commit 57b7c8f

Please sign in to comment.