欢迎来到天天文库
浏览记录
ID:40752878
大小:58.67 KB
页数:4页
时间:2019-08-07
《POCO C++库学习和分析 -- 随机数和数字摘要》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、POCOC++库学习和分析-- 随机数和数字摘要 在程序设计时,有时候我们需要生成随机数和数字摘要。在Poco库中,也提供了上述功能,下面我们一一叙述:1.随机数生成 Poco中生成随机数的类为Poco::Random类。它根据PRNG(pseudorandomnumbergenerator )算法设计,采用了一个累加的非线性反馈算法。PRNG算法可以产生0~2^31之间的随机数整数。 在接口上Poco::Random提供了一些函数,可以使使用者直接得到其他形式的随机数。如char, b
2、ool,float和double类型。另外Poco库中还提供了RandomInputStream类,用于Poco::Random类的流操作。成员函数: 1.voidseed(Poco::UInt32seed) 根据给定的种子值生成随机数。 2.voidseed() 使用任意值(从RandomInputStream类中获取)生成随机数。 3.默认的构造时,Poco::Random类采用当前的时间和日期生成随机数。如果想要更好的随机效果,需要显式的调用seed()方法
3、 4.UInt32next() 返回0~2^31之间的随机整数 5.UInt32next(UInt32n) 返回0~n之间的随机整数 6.charnextChar() 返回随机Char值 7.boolnextBool() 返回随机bool值 8.floatnextFloat() 返回随机float值,范围0~1 9. doublenextDouble() 返回随机double值,范围0~1 下
4、面是关于Random的一个例子:[cpp] viewplaincopy1.#include "Poco/Random.h" 2.#include "Poco/RandomStream.h" 3.#include 4.using Poco::Random; 5.using Poco::RandomInputStream; 6.int main(int argc, char** argv) 7.{ 8. Random rnd; 9. rnd.seed(); 10.
5、 std::cout << "Random integer: " << rnd.next() << std::endl; 11. std::cout << "Random digit: " << rnd.next(10) << std::endl; 12. std::cout << "Random char: " << rnd.nextChar() << std::endl; 13. std::cout << "Random bool: " << rnd.nextBool() << std::
6、endl; 14. std::cout << "Random double: " << rnd.nextDouble() << std::endl; 15. RandomInputStream ri; 16. std::string rs; 17. ri >> rs; 18. return 0; 19.} 2.密码散列 下面这段是Wiki上关于密码散列的介绍: Acryptographichashfunctionisahashfunctionwith c
7、ertainadditionalsecuritypropertiestomakeitsuitablefor useasaprimitiveinvariousinformationsecurityapplications, suchasauthenticationandmessageintegrity.Ahash functiontakesalongstring(ormessage)ofanylengthas inputandproducesafixedlengthstringasoutput, sometimeste
8、rmedamessagedigestoradigitalfingerprint. Wikipedia2.1概述 密码散列(cryptographichash)是将目标文本转换成具有相同长度的、不可逆的杂凑字符串(或叫做消息摘要)。它有两个特点: 1、哈希算法往往被设计成生成具有相同长度的文本 2、哈希算法是不可逆的
此文档下载收益归作者所有