| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- //
- // distribution.cpp
- // shared_random_generator
- //
- // Created by Sam Jaffe on 3/25/23.
- // Copyright © 2023 Sam Jaffe. All rights reserved.
- //
- #include "random/distribution.h"
- #include <iostream>
- #include <random>
- #include "random/device.h"
- namespace engine::random {
- template <typename Rand>
- Uniform<Rand>::Uniform(Rand min)
- : Uniform(min, std::numeric_limits<Rand>::max()) {}
- template <typename Rand>
- Uniform<Rand>::Uniform(Rand min, Rand max) : min_(min), max_(max) {}
- template <typename Rand>
- auto Uniform<Rand>::operator()(Device & device) const -> result_type {
- if constexpr (std::is_floating_point_v<Rand>) {
- return std::uniform_real_distribution<Rand>(min_, max_)(device);
- } else {
- return std::uniform_int_distribution<Rand>(min_, max_)(device);
- }
- }
- template <typename Rand> void Uniform<Rand>::describe(std::ostream & os) const {
- constexpr char close = std::is_floating_point_v<Rand> ? ')' : ']';
- os << "Uniform[" << min_ << ',' << max_ << close;
- }
- template class Uniform<size_t>;
- template class Uniform<double>;
- template class Uniform<int32_t>;
- template class Uniform<uint32_t>;
- }
|