Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Dec 13, 2023
1 parent 5bb57f8 commit 53d1774
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions include/boost/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <boost/random/subtract_with_carry.hpp>
#include <boost/random/taus88.hpp>
#include <boost/random/xor_combine.hpp>
#include <boost/random/splitmix64.hpp>

// misc
#include <boost/random/generate_canonical.hpp>
Expand Down
48 changes: 20 additions & 28 deletions include/boost/random/splitmix64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* This is a fixed-increment version of Java 8's SplittableRandom generator
* See http://dx.doi.org/10.1145/2714064.2660195 and
* http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
* It is a very fast generator passing BigCrush, and it can be useful if
* for some reason you absolutely want 64 bits of state; otherwise, we
* rather suggest to use a xoroshiro128+ (for moderately parallel
* computations) or xorshift1024* (for massively parallel computations)
* generator.
*/

#ifndef BOOST_RANDOM_SPLITMIX64_HPP
Expand All @@ -21,15 +13,23 @@
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <random>
#include <array>
#include <string>
#include <ios>
#include <iostream>
#include <type_traits>

namespace boost { namespace random {

/**
* This is a fixed-increment version of Java 8's SplittableRandom generator
* See http://dx.doi.org/10.1145/2714064.2660195 and
* http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html
* It is a very fast generator passing BigCrush, and it can be useful if
* for some reason you absolutely want 64 bits of state; otherwise, we
* rather suggest to use a xoroshiro128+ (for moderately parallel
* computations) or xorshift1024* (for massively parallel computations)
* generator.
*/
class splitmix64
{
private:
Expand Down Expand Up @@ -111,12 +111,7 @@ class splitmix64

inline friend bool operator==(const splitmix64& lhs, const splitmix64& rhs) noexcept
{
if (lhs.state_ == rhs.state_)
{
return true;
}

return false;
return lhs.state_ == rhs.state_;
}

inline friend bool operator!=(const splitmix64& lhs, const splitmix64& rhs) noexcept
Expand All @@ -128,25 +123,22 @@ class splitmix64
inline friend std::basic_ostream<CharT,Traits>& operator<<(std::basic_ostream<CharT,Traits>& ost,
const splitmix64& e)
{
std::string sstate = std::to_string(e.state_);
for (const auto i : sstate)
{
ost << i;
}

ost << e.state_;
return ost;
}

template <typename CharT, typename Traits>
friend std::basic_istream<CharT,Traits>& operator>>(std::basic_istream<CharT,Traits>& ist,
splitmix64& e)
inline friend std::basic_istream<CharT,Traits>& operator>>(std::basic_istream<CharT,Traits>& ist,
splitmix64& e)
{
std::string sstate;
for (std::size_t i {}; i <= std::numeric_limits<std::uint64_t>::digits10; ++i)
CharT val;
while (ist >> val)
{
CharT val;
ist >> val >> std::ws;
sstate.push_back(val);
if (std::isdigit(val))
{
sstate.push_back(val);
}
}

e.state_ = std::strtoull(sstate.c_str(), nullptr, 10);
Expand Down

0 comments on commit 53d1774

Please sign in to comment.