草庐IT

random_integer

全部标签

c++ - int8_t 和 char : converts between pointers to integer types with different sign - but it doesn't

我正在处理一些嵌入式代码,并且正在从头开始编写一些新东西,因此我更愿意坚持使用uint8_t、int8_t等类型。然而,当移植一个函数时:voidfunctionName(char*data)到:voidfunctionName(int8_t*data)在将文字字符串传递给函数时,我收到编译器警告“在指向具有不同符号的整数类型的指针之间转换”。(即调用functionName("putthistextin");时)。现在,我明白了为什么会发生这种情况,并且这些行只是调试,但我想知道人们认为什么是最合适的处理方式,而不是对每个文字字符串进行类型转换。在实践中,我不认为一揽子类型转换比使用

c++ - scanf 与 cin : string as integer processing

我有一个输入字符串“0100”为什么scanf("%i",&n);返回64而cin>>n;给我100?为什么cin以十进制值思考,而scanf以八进制值思考? 最佳答案 Fortheispecifier:  Anynumberofdigits,optionallyprecededbyasign(+or-).Decimaldigitsassumedbydefault(0-9),buta0prefixintroducesoctaldigits(0-7),and0xintroduceshexadecimaldigits(0-f).-sca

c++ - 'default_random_engine' 不是 std 的成员

我发现了很多关于这个主题的问题,但所有问题似乎都与不使用C++11编译有关。我的代码是#includeintmain(intargc,char*argv[]){std::default_random_enginegenerator;return0;}即使我用编译gcc-std=c++0xtestmain.cpp给出default_random_engine不是std成员的错误。该程序是在远程机器上编译的,我自己不维护,但gcc-v生成4.4.7版本。有什么想法吗? 最佳答案 对于其他人:检查您是否真的在#include中包含了随机数

c++ - 在类中使用 C++0x TR1 random 以降低开销

我正在使用VC2010并尝试通过将随机定义放置在每个类实例的构造函数中,然后根据需要从那里调用来降低某些函数的开销和重复代码。我现在所拥有的,简化后的是:#include#includemt19937eng(GetTickCount());classCycles{intline;normal_distributionrand_norm;variate_generator>r_norm;public:Cycles():rand_norm(0.85,0.05),r_norm(eng,rand_norm){line=0;}}不幸的是,这不起作用,我最终遇到了这个错误:\vc\include\

Python实现随机森林(Random Forest)

💥项目专栏:【Python实现经典机器学习算法】附代码+原理介绍文章目录前言一、基于原生Python实现随机森林(RandomForest)二、Bagging算法原理介绍三、随机森林的算法原理四、算法实现4.1导包4.2定义随机数种子4.3定义随机森林模型4.3.1模型训练4.3.2模型预测4.3.3模型分数4.3.4RandomForest模型

c++ - 现实程序中来自 c++ <random> 库的随机数生成器

我正在了解这个库,它在很多方面改进了旧的rand和srand。但是对于rand,很明显只有一个随机数生成器在使用rand时被调用和更新,无论它在您的程序中的何处。使用新方法时,我不确定如何以良好的风格有效地模仿这种行为。例如,如果我想要掷骰子,并且模仿在主过程中编写的在线示例,我用这样的方法编写了一个对象:classfoo{public:floatgetDiceRoll(){std::random_devicerd;std::default_random_enginee1(rd());std::uniform_int_distributionuniform_dist(1,6);retu

C++0x random_device 'std::runtime_error'

我是C++初学者,我对C++0x随机数生成器有疑问。我想使用Mersennetwister引擎来生成随机int64_t数字,并且我使用我之前找到的一些信息编写了一个函数:#include#includeint64_tMyRandomClass::generateInt64_t(int64_tminValue,int64_tmaxValue){std::random_devicerd;std::default_random_enginee(rd());unsignedchararr[8];for(unsignedinti=0;i(arr[0])|static_cast(arr[1])(a

c++ - 警告 : Comparison between signed and unsigned integer expression

我在codepad.org上运行以下代码时出现此错误。“在成员函数‘doubleXchange::getprice(std::string)’中:第87行:警告:有符号和无符号整数表达式之间的比较”这是我的代码:#include#include#includeusingnamespacestd;classXchange{public:Xchange();//doesnothing(?)doublegetprice(stringsymbol);private:vectorstocks;};doubleXchange::getprice(stringsymbol){for(inti=0;i

c++ - 如何让Boost::random和Matlab产生相同的随机数

为了检查我的C++代码,我希望能够让Boost::Random和Matlab产生相同的随机数。所以对于Boost,我使用代码:boost::mt19937var(static_cast(std::time(0)));boost::uniform_intdist(1,6);boost::variate_generator>die(var,dist);die.engine().seed(0);for(inti=0;i产生(程序的每次运行):4456464634对于matlab,我使用:RandStream.setDefaultStream(RandStream('mt19937ar','s

c++ - std::default_random_engine 即使改变种子也会生成相同的值?

我正在尝试实现一个类,该类将用作随机库的某种包装器,以便我可以(我认为)在我的代码中的其他地方以更直观的方式使用它的对象和函数。在我的标题中有这样的内容:classRandomDevice{private:unsignedlongrand_seed;default_random_engineengine;public:RandomDevice(unsignedlongn);intrandInt(intmin,intmax);};然后在.cpp文件中我实现了这两个函数(constructor和randInt),如下所示:RandomDevice::RandomDevice(unsigne