2
* Copyright 2008-2011 NVIDIA Corporation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include <thrust/random/linear_congruential_engine.h>
18
#include <thrust/random/detail/mod.h>
19
#include <thrust/random/detail/random_core_access.h>
28
template<typename UIntType, UIntType a, UIntType c, UIntType m>
29
linear_congruential_engine<UIntType,a,c,m>
30
::linear_congruential_engine(result_type s)
33
} // end linear_congruential_engine::linear_congruential_engine()
36
template<typename UIntType, UIntType a, UIntType c, UIntType m>
37
void linear_congruential_engine<UIntType,a,c,m>
40
if((detail::mod<UIntType, 1, 0, m>(c) == 0) &&
41
(detail::mod<UIntType, 1, 0, m>(s) == 0))
42
m_x = detail::mod<UIntType, 1, 0, m>(1);
44
m_x = detail::mod<UIntType, 1, 0, m>(s);
45
} // end linear_congruential_engine::seed()
48
template<typename UIntType, UIntType a, UIntType c, UIntType m>
49
typename linear_congruential_engine<UIntType,a,c,m>::result_type
50
linear_congruential_engine<UIntType,a,c,m>
53
m_x = detail::mod<UIntType,a,c,m>(m_x);
55
} // end linear_congruential_engine::operator()()
58
template<typename UIntType, UIntType a, UIntType c, UIntType m>
59
void linear_congruential_engine<UIntType,a,c,m>
60
::discard(unsigned long long z)
62
thrust::random::detail::linear_congruential_engine_discard::discard(*this,z);
63
} // end linear_congruential_engine::discard()
66
template<typename UIntType, UIntType a, UIntType c, UIntType m>
67
template<typename CharT, typename Traits>
68
std::basic_ostream<CharT,Traits>& linear_congruential_engine<UIntType,a,c,m>
69
::stream_out(std::basic_ostream<CharT,Traits> &os) const
71
typedef std::basic_ostream<CharT,Traits> ostream_type;
72
typedef typename ostream_type::ios_base ios_base;
74
// save old flags & fill character
75
const typename ios_base::fmtflags flags = os.flags();
76
const CharT fill = os.fill();
78
os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
79
os.fill(os.widen(' '));
81
// output one word of state
84
// restore flags & fill character
92
template<typename UIntType, UIntType a, UIntType c, UIntType m>
93
template<typename CharT, typename Traits>
94
std::basic_istream<CharT,Traits>& linear_congruential_engine<UIntType,a,c,m>
95
::stream_in(std::basic_istream<CharT,Traits> &is)
97
typedef std::basic_istream<CharT,Traits> istream_type;
98
typedef typename istream_type::ios_base ios_base;
101
const typename ios_base::fmtflags flags = is.flags();
103
is.flags(ios_base::dec);
105
// input one word of state
115
template<typename UIntType, UIntType a, UIntType c, UIntType m>
116
bool linear_congruential_engine<UIntType,a,c,m>
117
::equal(const linear_congruential_engine<UIntType,a,c,m> &rhs) const
119
return m_x == rhs.m_x;
123
template<typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_>
125
bool operator==(const linear_congruential_engine<UIntType_,a_,c_,m_> &lhs,
126
const linear_congruential_engine<UIntType_,a_,c_,m_> &rhs)
128
return detail::random_core_access::equal(lhs,rhs);
132
template<typename UIntType, UIntType a, UIntType c, UIntType m>
133
bool operator!=(const linear_congruential_engine<UIntType,a,c,m> &lhs,
134
const linear_congruential_engine<UIntType,a,c,m> &rhs)
136
return !(lhs == rhs);
140
template<typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_,
141
typename CharT, typename Traits>
142
std::basic_ostream<CharT,Traits>&
143
operator<<(std::basic_ostream<CharT,Traits> &os,
144
const linear_congruential_engine<UIntType_,a_,c_,m_> &e)
146
return detail::random_core_access::stream_out(os,e);
150
template<typename UIntType_, UIntType_ a_, UIntType_ c_, UIntType_ m_,
151
typename CharT, typename Traits>
152
std::basic_istream<CharT,Traits>&
153
operator>>(std::basic_istream<CharT,Traits> &is,
154
linear_congruential_engine<UIntType_,a_,c_,m_> &e)
156
return detail::random_core_access::stream_in(is,e);