Re: [Cppcms-users] how to use cppcms::urandom_device to generate a random string and output it as a
Brought to you by:
artyom-beilis
From: Marcel H. <ke...@co...> - 2012-05-23 11:11:14
|
Am 23.05.2012 13:03, schrieb Zheng Ping: > Hi, all: > I am a green hand to cppcms. I want to generate a random string by > using cppcms::urandom_device. my codes are: > char buf[32]; > cppcms::urandom_device random_device; > random_device.generate(buf, 16); > std::string output(buf); > std::cout << output << std::endl; > .... ... > The above codes will output garbled codes, I don't know how to get > readable random string by using cppcms::urandom_device, who can give > me an advise? > > -- > with kind regards > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users what does a random device does? It "prints" out chars in range from 0 to 1 << CHAR_BIT -1 What is "printable"? http://www.asciitable.com/ nums in range from 33 - 126 and some extended ascii codes. A char is nothing different than unsigned int with the length of CHAR_BIT ("normally" 8). What you can do is, define an array with all the letters you want to print and then create a random number in range from 0 to array.length() and then print it out via direct array access. Hope it helpes a bit. Regards |