#include <iostream>
#include <boost/random/random_device.hpp>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
using namespace std; int randString()
{
/*<< We first define the characters that we're going
to allow. This is pretty much just the characters
on a standard keyboard.
>>*/
std::string chars(
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"1234567890"
"!@#$%^&*()"
"`~-_=+[{]}\\|;:'\",<.>/? ");
/*<< We use __random_device as a source of entropy, since we want
passwords that are not predictable.
>>*/
boost::random::random_device rng;
/*<< Finally we select 8 random characters from the
string and print them to cout.
>>*/
boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
for(int i = 0; i < 8; ++i) {
std::cout << chars[index_dist(rng)];
}
std::cout << std::endl;
}
int main()
{
cout<<"===============rand String==============="<<endl;
randString(); cout<<"===============rand number==============="<<endl;
typedef boost::mt19937 RNGType;
RNGType rng;
rng.seed(time(NULL));
boost::uniform_int<> one_to_six( 99999, 999999 );
boost::variate_generator< RNGType, boost::uniform_int<> >
dice(rng, one_to_six);
for ( int i = 0; i < 6; i++ )
{
int n = dice();
cout << n << endl;
}
}

使用boost库生成随机字符串 随机数,生成随机数还是比较方便,随机字符串倒没觉得比rand方便多少,反而麻烦

使用boost库生成 随机数 随机字符串的更多相关文章

  1. JMeter - 生成随机数/随机字符串/随机变量/随机日期

    1. Random - 随机数 1.1 作用 1.2 声明 1.3 例子 2. __RandomDate - 随机日期 2.1 作用 2.2 声明参数 2.3 例子 3. RandomString - ...

  2. C#使用 RNGCryptoServiceProvider 生成强随机字符串

    为了生成更加可靠的随机数,微软在System.Security.Cryptography命名空间下提供一个名为system.Security.Cryptography.RNGCryptoService ...

  3. (五)boost库之随机数random

    (五)boost库之随机数random boost库为我们提供了许多的日常随机数生成器: 1.uniform_smallint:在小整数域内的均匀分布 2.uniform_int:在整数域上的均匀分布 ...

  4. 笔记-9:使用random库生成随机数

    random:主要目的是生成随机数 函数 说明 seed(a=None) 初始化随机数,默认值为当前系统时间 random() 生成一个[0.0,1.0)之间的随机数小数 randint(a,b) 生 ...

  5. boost库生成文件命名和编译

    生成文件命名规则:boost中有许多库,有的库需要编译.而有的库不需要编译,只需包含头文件就可以使用.编译生成的文件名字普遍较长,同一个库根据编译链接选项不同,又可以生成多个不同名字的文件.生成的文件 ...

  6. Java实验--课上提到的随机数生成原理简单实现(不利用库生成随机数的简单算法)

    对于随机数的实验,根据课程上的教程,有如下的公式: 对应的变量参数的说明: 其中对应的Mouduls变量对应的就是公式中a的值,在公式中的含义就是相当于要循环多少个数才重复的一个值. Multipli ...

  7. 接口自动化CSV文件生成超长随机字符串--java接口方法

    public class STR { private static String Builderrud(int a){ StringBuilder builder= new StringBuilder ...

  8. PHP生成指定随机字符串的简单实现方法

    /** * @param string $type * @param $length * @return string */ function randomString($type="num ...

  9. .net生成随机字符串

    生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...

随机推荐

  1. 讯飞语音识别Android-Demo

    import java.io.UnsupportedEncodingException; import android.app.Activity; import android.os.Bundle; ...

  2. VC++的project文件

    VC++的project文件说明: *.dsp:是VC++的项目文件,文本格式. *.dsw:是工作区文件,它能够指向一个或多个.dsp文件. *.clw:是 ClassWizard信息文件,实际上是 ...

  3. Logical Volume Manager (Linux)

    http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux) Logical Volume Manager (Linux) From Wiki ...

  4. 编码知识 (Unicode、UTF-8、ANSI)

    1. ASCII码 我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出256种状态,这被称为一个字节(byte). ...

  5. ScrollView滑动的监听

    ScrollView滑动的监听 有时候我们须要监听ScrollView的滑动事件.来完毕业务需求. 第一种: 能够直接实现OnTouchListener接口.在这里面写你所须要的操作 scrollVi ...

  6. Apache Server与多个独立Tomcat集成

    取经自http://www.ramkitech.com/2012/03/virtual-host-apache-httpd-server-tomcat.html 继续干Tomcat和Apache Se ...

  7. 当CSDN携手Markdown

    当CSDN携手Markdown Tags: CSDN Markdown 当CSDN携手Markdown Markdown CSDN-Markdown 也不知道是不是基于 Github 崛起的因素,Ma ...

  8. WPF控件模板和数据模板 - 醉意人间

    来自:http://www.th7.cn/Program/WPF/2011/12/21/51676.shtml ControlTemplate用于描述控件本身. 使用TemplateBinding来绑 ...

  9. 【BZOJ3505】[Cqoi2014]数三角形 组合数

    [BZOJ3505][Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. ...

  10. 建立FTP服务器(FTP服务器名要与创建的用户名一致)

    1新建用户 2. 3.建立FTP