使用boost库生成 随机数 随机字符串
#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库生成 随机数 随机字符串的更多相关文章
- JMeter - 生成随机数/随机字符串/随机变量/随机日期
1. Random - 随机数 1.1 作用 1.2 声明 1.3 例子 2. __RandomDate - 随机日期 2.1 作用 2.2 声明参数 2.3 例子 3. RandomString - ...
- C#使用 RNGCryptoServiceProvider 生成强随机字符串
为了生成更加可靠的随机数,微软在System.Security.Cryptography命名空间下提供一个名为system.Security.Cryptography.RNGCryptoService ...
- (五)boost库之随机数random
(五)boost库之随机数random boost库为我们提供了许多的日常随机数生成器: 1.uniform_smallint:在小整数域内的均匀分布 2.uniform_int:在整数域上的均匀分布 ...
- 笔记-9:使用random库生成随机数
random:主要目的是生成随机数 函数 说明 seed(a=None) 初始化随机数,默认值为当前系统时间 random() 生成一个[0.0,1.0)之间的随机数小数 randint(a,b) 生 ...
- boost库生成文件命名和编译
生成文件命名规则:boost中有许多库,有的库需要编译.而有的库不需要编译,只需包含头文件就可以使用.编译生成的文件名字普遍较长,同一个库根据编译链接选项不同,又可以生成多个不同名字的文件.生成的文件 ...
- Java实验--课上提到的随机数生成原理简单实现(不利用库生成随机数的简单算法)
对于随机数的实验,根据课程上的教程,有如下的公式: 对应的变量参数的说明: 其中对应的Mouduls变量对应的就是公式中a的值,在公式中的含义就是相当于要循环多少个数才重复的一个值. Multipli ...
- 接口自动化CSV文件生成超长随机字符串--java接口方法
public class STR { private static String Builderrud(int a){ StringBuilder builder= new StringBuilder ...
- PHP生成指定随机字符串的简单实现方法
/** * @param string $type * @param $length * @return string */ function randomString($type="num ...
- .net生成随机字符串
生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...
随机推荐
- vbox在共享文件夹设置链接报错Protocol error问题
环境: 基于VBox 的 vagrant (centos版本)开发环境. 问题: Virtualbox 虚拟机(centOS)中,在进行go程序编译的时候,需要设置一个链接符,然后得到了如下的错误: ...
- ASP.Net MVC开发基础学习笔记(8):新建数据页面
前言 前面解说了怎样创建一个查询页面并给查询页面加入排序.搜索及分页功能.今天我们来讲讲怎样向这个列表加入数据. 解说的顺序将依照加入数据的步骤的时间顺序来进行,方便大家理清逻辑关系. 本节将涉 ...
- 如何防范SQL注入式攻击
一.什么是SQL注入式攻击? 所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者 ...
- construct-binary-tree-from-preorder-and-inorder-traversal——前序和中序求二叉树
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume tha ...
- js 字符串常用方法
数组方面 1.push:向数组尾部增加内容,返回的是新数组的长度. var arr = [1,2,3]; console.log(arr); var b = arr.push(4); console. ...
- 1.excel如何让一列的数都乘以固定值
让B列等于A列乘以39.37 1.我们先选中B列中要编辑的单元: 2.再在编辑栏中输入公式:=A2*39.37 (PS:*号即表示是×号) 3.公式输入后,按下快捷键:CTRL+回车:记住一定要 ...
- bootstrap之鼠标操作
TouchLongClick package io.appium.android.bootstrap.handler; import android.os.SystemClock; import co ...
- ZOJ 3156 Taxi (二分匹配+二分查找)
题目链接:Taxi Taxi Time Limit: 1 Second Memory Limit: 32768 KB As we all know, it often rains sudde ...
- linux中vi编辑器(转载)
三种模式相互切换 在命令终端输入vi进入vi编辑器. 命令模式:进入编辑器即进入命令模式, 输入模式:在命令模式下输入“i ”进入输入模式: 末行模式:按“:”进入末行模式: 在输入模式切换至末行模式 ...
- 当半导体的工艺制程走到7nm后
https://mp.weixin.qq.com/s/LjFTtEKFX2o8kLjn3y6GbQ 深度学习的异构加速技术1:效率因通用而怠,构架为AI而生 一方面,当半导体的工艺制程走到7nm后,已 ...