NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
randInt.hpp
Go to the documentation of this file.
1
30#pragma once
31
32#include <algorithm>
33#include <random>
34#include <string>
35
38#include "NumCpp/Core/Shape.hpp"
39#include "NumCpp/NdArray.hpp"
41
42namespace nc::random
43{
44 namespace detail
45 {
46 //============================================================================
47 // Method Description:
60 template<typename dtype, typename GeneratorType = std::mt19937>
62 {
64
65 if (inLow == inHigh)
66 {
67 THROW_INVALID_ARGUMENT_ERROR("input low value must be less than the input high value.");
68 }
69 else if (inLow > inHigh)
70 {
71 std::swap(inLow, inHigh);
72 }
73
74 std::uniform_int_distribution<dtype> dist(inLow, inHigh - 1);
75 return dist(generator);
76 }
77
78 //============================================================================
79 // Method Description:
93 template<typename dtype, typename GeneratorType = std::mt19937>
95 {
97
98 if (inLow == inHigh)
99 {
100 THROW_INVALID_ARGUMENT_ERROR("input low value must be less than the input high value.");
101 }
102 else if (inLow > inHigh - 1)
103 {
104 std::swap(inLow, inHigh);
105 }
106
108
109 std::uniform_int_distribution<dtype> dist(inLow, inHigh - 1);
110
111 std::for_each(returnArray.begin(),
112 returnArray.end(),
113 [&dist, &generator](dtype& value) -> void { value = dist(generator); });
114
115 return returnArray;
116 }
117 } // namespace detail
118
119 //============================================================================
120 // Method Description:
132 template<typename dtype>
137
138 //============================================================================
139 // Method Description:
152 template<typename dtype>
157} // namespace nc::random
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_INTEGER(dtype)
Definition StaticAsserts.hpp:43
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
dtype randInt(GeneratorType &generator, dtype inLow, dtype inHigh=0)
Definition randInt.hpp:61
Definition Random/bernoulli.hpp:41
dtype randInt(dtype inLow, dtype inHigh=0)
Definition randInt.hpp:133
std::mt19937_64 generator_
generator function
Definition generator.hpp:35
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59