随机过程给定种子,得到的结果总是一样的
来源:互联网 发布:淘宝手机端显示宝贝 编辑:程序博客网 时间:2024/04/29 21:17
如题。
以下是一段产生不重复的随机数的代码:
#include <stdio.h>#include <stdlib.h>#include <vector>#include <algorithm>bool sortIntVector(int v1, int v2);int main(){ std::vector<int> v_randInt; int seed = 9; int temp; int i = 0; while(v_randInt.size() < 20) { srand(seed + i); temp = rand()%100; if(i%2 == 0) { i ++; continue; } i++; temp += i + 5; temp = temp%100; while(find(v_randInt.begin(),v_randInt.end(),temp) < v_randInt.end()) { temp = rand()%100; } v_randInt.push_back(temp); } sort( v_randInt.begin(),v_randInt.end(), sortIntVector); for(std::vector<int>::iterator i = v_randInt.begin(); i < v_randInt.end() ; i++) printf("%d\n",i[0]); //system("pause"); return 0;}bool sortIntVector(int v1, int v2){ return v1 < v2;//升序排列 }
多次执行的结果是一致的:
3
6
12
14
20
23
29
31
37
40
46
55
63
72
78
80
86
89
95
97
- 随机过程给定种子,得到的结果总是一样的
- C#的随机种子
- Java的随机种子
- 像傻逼一样坚持,总会得到牛逼的结果
- 带随机种子的javascript随机函数
- 波形仿真的结果总是一样,虽然我改动了相关的IO与设置
- 关于种子数的随机判断大小
- 从零开始—随机种子的应用
- lua 中随机种子的设定
- 得到肯定总是好的
- 得到随机排序结果
- 得到随机排序结果
- 结果都是一样的java
- 得到一组随机的字符
- matlab随机函数的种子状态的保存与恢复
- 得到给定扩展名的文件图标
- 得到一个给定url的内容
- 得到给定扩展名的文件图标
- Base64与图片互转
- 去上海
- 用 jstl 取 Date(java.util.Date) 的年的值 和月的值
- 表达式括号匹配
- DRUPAL 分页
- 随机过程给定种子,得到的结果总是一样的
- 转: JNI设计实践之路
- 队列的顺序存储结构与操作
- 无法正确获取屏幕尺寸【一个诡异的问题】
- JS CSS 压缩工具(GUI界面)
- 队列的链式存储结构与操作
- 数组常用方法的总结
- Visual Studio 11:色彩在RC版中又回归了
- 动态折半查找