ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
UniformRandom.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Uniform Random Distribution Header File
18
19Author: Alex Reynolds
20*/
21#ifndef UNIFORM_RANDOM_HPP
22#define UNIFORM_RANDOM_HPP
23
24#include <random>
25
26#include "data_management/GraphTreeObject.h"
27#include "data_management/DataIO.hpp"
28
29namespace modelspace {
30
31 /**
32 * @brief Class to generate random numbers according to uniform distribution
33 *
34 * This function generates a random uniform distribution draw according to
35 * the mt19937 engine and a std::uniform_distribution. It produces random
36 * numbers according to the min, max, and seed set in the constructor. Min
37 * and max may be modified via standard setters mean and std.
38 *
39 * If numbers are entered backwards, will flip them
40 */
41 template<typename T>
42 class UniformRandom : clockwerk::GraphTreeObject {
43 public:
44 /// @brief Constructor for the normal random distribution
45 /// @param set_min The minimum value in the distribution
46 /// @param set_max The maximum value in the distribution
47 /// @param seed Seed for the RNG -- Defaults to zero
48 UniformRandom(T set_min, T set_max, unsigned int seed = 0);
49 ~UniformRandom() {}
50
51 T operator () ();
52
53 /// @brief The mean of the random output. Can be get/set
54 clockwerk::DataIO<T> min = clockwerk::DataIO<T>(this, "min");
55
56 /// @brief The standard deviation of the random output. Can be get/set
57 clockwerk::DataIO<T> max = clockwerk::DataIO<T>(this, "max");
58 protected:
59 std::mt19937 _engine;
60 std::uniform_real_distribution<double> _distribution;
61 };
62
63 template <typename T>
64 UniformRandom<T>::UniformRandom(T set_min, T set_max, unsigned int seed)
65 : _engine{seed}, _distribution(0, 1.0) {
66 // Handle the case where someone put numbers in backwards. Someone will.
67 if(set_min > set_max) {
68 min(set_max);
69 max(set_min);
70 } else {
71 min(set_min);
72 max(set_max);
73 }
74 }
75
76 template <typename T>
77 T UniformRandom<T>::operator () () {
78 // Calculate our distribution as
79 // val = min + (max - min)*rng
80
81 return min() + _distribution(_engine)*(max() - min());
82 }
83
84}
85
86#endif
Class for inter-object communication.
Definition DataIO.hpp:46
Base class for object organization.
Definition GraphTreeObject.h:87
Class to generate random numbers according to uniform distribution.
Definition UniformRandom.hpp:42
UniformRandom(T set_min, T set_max, unsigned int seed=0)
Constructor for the normal random distribution.
Definition UniformRandom.hpp:64
clockwerk::DataIO< T > max
The standard deviation of the random output. Can be get/set.
Definition UniformRandom.hpp:57
clockwerk::DataIO< T > min
The mean of the random output. Can be get/set.
Definition UniformRandom.hpp:54
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18