2个回答
展开全部
<random>头文件包含以下声明(数字对应的是ISO C++标准文档的章节号):
#include <initializer_list>
namespace std {
// 26.5.3.1, class template linear_congruential_engine
template<class UIntType, UIntType a, UIntType c, UIntType m>
class linear_congruential_engine;
// 26.5.3.2, class template mersenne_twister_engine
template<class UIntType, size_t w, size_t n, size_t m, size_t r,
UIntType a, size_t u, UIntType d, size_t s,
UIntType b, size_t t,
UIntType c, size_t l, UIntType f>
class mersenne_twister_engine;
// 26.5.3.3, class template subtract_with_carry_engine
template<class UIntType, size_t w, size_t s, size_t r>
class subtract_with_carry_engine;
// 26.5.4.2, class template discard_block_engine
template<class Engine, size_t p, size_t r>
class discard_block_engine;
// 26.5.4.3, class template independent_bits_engine
template<class Engine, size_t w, class UIntType>
class independent_bits_engine;
// 26.5.4.4, class template shuffle_order_engine
template<class Engine, size_t k>
class shuffle_order_engine;
// 26.5.5, engines and engine adaptors with predefined parameters
typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
minstd_rand0;
typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
minstd_rand;
typedef mersenne_twister_engine<uint_fast32_t,
32,624,397,31,0x9908b0df,11,0xffffffff,7,
0x9d2c5680,15,0xefc60000,18,1812433253
>
mt19937;
typedef mersenne_twister_engine<uint_fast64_t,
64,312,156,31,0xb5026f5aa96619e9,29,
0x5555555555555555,17,
0x71d67fffeda60000,37,
0xfff7eee000000000,43,
6364136223846793005>
mt19937_64;
typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
ranlux24_base;
typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
ranlux48_base;
typedef discard_block_engine<ranlux24_base, 223, 23>
ranlux24;
typedef discard_block_engine<ranlux48_base, 389, 11>
ranlux48;
typedef shuffle_order_engine<minstd_rand0,256>
knuth_b;
typedef implementation-defined
default_random_engine;
// 26.5.6, class random_device
class random_device;
// 26.5.7.1, class seed_seq
class seed_seq;
// 26.5.7.2, function template generate_canonical
template<class RealType, size_t bits, class URNG>
RealType generate_canonical(URNG& g);
// 26.5.8.2.1, class template uniform_int_distribution
template<class IntType = int>
class uniform_int_distribution;
// 26.5.8.2.2, class template uniform_real_distribution
template<class RealType = double>
class uniform_real_distribution;
// 26.5.8.3.1, class bernoulli_distribution
class bernoulli_distribution;
// 26.5.8.3.2, class template binomial_distribution
template<class IntType = int>
class binomial_distribution;
// 26.5.8.3.3, class template geometric_distribution
template<class IntType = int>
class geometric_distribution;
// 26.5.8.3.4, class template negative_binomial_distribution
template<class IntType = int>
class negative_binomial_distribution;
// 26.5.8.4.1, class template poisson_distribution
template<class IntType = int>
class poisson_distribution;
// 26.5.8.4.2, class template exponential_distribution
template<class RealType = double>
class exponential_distribution;
// 26.5.8.4.3, class template gamma_distribution
template<class RealType = double>
class gamma_distribution;
// 26.5.8.4.4, class template weibull_distribution
template<class RealType = double>
class weibull_distribution;
// 26.5.8.4.5, class template extreme_value_distribution
template<class RealType = double>
class extreme_value_distribution;
// 26.5.8.5.1, class template normal_distribution
template<class RealType = double>
class normal_distribution;
// 26.5.8.5.2, class template lognormal_distribution
template<class RealType = double>
class lognormal_distribution;
// 26.5.8.5.3, class template chi_squared_distribution
template<class RealType = double>
class chi_squared_distribution;
// 26.5.8.5.4, class template cauchy_distribution
template<class RealType = double>
class cauchy_distribution;
// 26.5.8.5.5, class template fisher_f_distribution
template<class RealType = double>
class fisher_f_distribution;
// 26.5.8.5.6, class template student_t_distribution
template<class RealType = double>
class student_t_distribution;
// 26.5.8.6.1, class template discrete_distribution
template<class IntType = int>
class discrete_distribution;
// 26.5.8.6.2, class template piecewise_constant_distribution
template<class RealType = double>
class piecewise_constant_distribution;
// 26.5.8.6.3, class template piecewise_linear_distribution
template<class RealType = double>
class piecewise_linear_distribution;
} // namespace std
展开全部
Random.h
#include<limits.h>
#include<time.h>
class Random
{
public:
Random(bool pseudo = true);
virtual ~Random();
double random_real();
int random_integer(int low, int high);
private:
int reseed();
int seed, multiplier, add_on;
};
int Random::reseed()
{
seed = seed * multiplier + add_on;
return seed;
}
Random::Random(bool pesudo)
{
if (pesudo)
seed = 1;
else
seed = time(NULL)%INT_MAX;
multiplier = 2743;
add_on = 5943;
}
Random::~Random()
{
}
double Random::random_real()
{
double max = INT_MAX + 1.0;
double temp = reseed();
if (temp < 0)
temp = temp +max;
return temp / max;
}
int Random::random_integer(int low, int high)
{
if (low < high)
return random_integer(high, low);
else
return ( (int)( (high - low + 1) * random_real() ) ) + low;
}
生成一个2000以内的随机数
srand ( (unsigned)time(0) + i);
temp = rand() % 2000;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询