(C/C++) 亂數應用
因為公司需要寫了一個亂數產生測試條件的小程式,再此紀錄下來
int _tmain(int argc, _TCHAR* argv[])
{
fstream file;
file.open("temp.csv", ios::out); int min = , max = , num = ;
cout << "please input max, min, num :" << endl;
cin >> max >> min >> num;
cout << "max = " << max << " min = " << min << " num = " << num << endl;
double rnd = (double)((rand() % ) + ) / ;
int step_range = (max - min) / ;
int i = ;
vector<int> temp; while (max > (step_range * i) + min){
temp.push_back((step_range * i) + min);
i++;
}
i--;
int index = ;
while (num){
int value = (rand() % ) + ;
double x = max / ((double)(rand() % ) + ) / ;
double res = value * x + temp[rand() % i + ];
while (res > max)
{
value = (rand() % ) + ;
x = max / ((double)(rand() % ) + ) / ;
res = value * x + temp[rand() % i];
}
file << index << "," << res << endl;
index++;
num--;
} system("pause");
return ;
}
因為條件內有上下限的限制所以先把條件範圍歸類成幾個區塊,但是在C++裡頭array沒辦法動態調整大小所以我用Vector
動態調整新增我的條件範圍
while (max > (step_range * i) + min){
temp.push_back((step_range * i) + min);
i++;
}
(C/C++) 亂數應用的更多相关文章
- [亂數] <細說> C/C++ 亂數基本使用與常見問題
陸陸續續寫了 EA 一.二年,以前亂數引導文回頭看時才發現,怎麼有這麼多細節的錯誤.沒系統. 這篇文章主要引導初學者使用亂數,同時附上常被翻出來討論的議題,C/C++適用,唯以 C 語言撰之. 也由 ...
- Android常用元件
本文来源于 http://blog.csdn.net/wxhlinux/article/details/8601170#comments 1.4 Android應用程式元件1.4.1 Activi ...
- 鸟哥的linux私房菜---非常好的linux基础网址【转】
转自:http://linux.vbird.org/linux_basic/0320bash.php 在 Linux 的環境下,如果你不懂 bash 是什麼,那麼其他的東西就不用學了!因為前面幾章我們 ...
- Browser 與 Server 持續同步的作法介紹 (Polling, Comet, Long Polling, WebSocket)长连接
對 Comet 的懵懂 記得兩年多前,第一次看到 Gmail 中的 GTalk 覺得很好奇:「咦?線上聊天且是 Google 的熱門系統,只用傳統的 AJAX 應該會操爆伺服器吧?」很幸運的,當時前公 ...
- [hadoop源代码解读] 【SequenceFile】
SequeceFile是Hadoop API提供的一种二进制文件支持.这种二进制文件直接将<key, value>对序列化到文件中.一般对小文件可以使用这种文件合并,即将文件名作为key, ...
- 網站SSL加密原理簡介(2张图,握手有9个步骤,解释的很清楚)
Secure Socket Layer說明 SSL是Secure Socket Layer(安全套接層協議)的縮寫,可以在Internet上提供秘密性傳輸.最早是Netscape公司所提出,SSL的目 ...
- JavaScript基礎知識
JavaScript基礎知識 1.標籤組使用 <script charset='utf-8' //設置字元集 defet //使腳本延遲到文檔解析完成,Browser已忽略 language=' ...
- 一起來玩鳥 Starling Framework(2)效能測試以及Image與Texture
上一篇我們放了一個Quad與TextField在舞台上慢慢轉.眼尖的可能會發現轉起來邊緣有點鋸齒,這可以透過設定Starling的反鋸齒來解決,在Main.as裡,新增了_starling之後,可以加 ...
- 【NS2】NS2 教學手冊(转载)
之前做毕设的时候搜索NS2的相关资料,发现这个里面涵盖很广,特此收藏,感谢原作者的辛勤劳作. NS2 教學手冊 ( NS2 Learning Guide) [快速連結區] My works 中文影音 ...
随机推荐
- mysql5.6配置semi_sync
测试环境:Red Hat Enterprise Linux Server release 6.3 (Santiago)Server version: 5.6.22-log MySQL Communit ...
- [SoapUI] JsonPath 语法 与 XPath 对比
XPath JSONPath Description / $ the root object/element . @ the current object/element / . or [] chil ...
- HTML的DOM树结构
在面试连续跪了两轮后,我觉得两个月的前端白学了.主要的原因是学而不思,知识是零散的,并没有组织起来.于是,我决定从今天起,复习并总结一下前端的知识点. 一般的网页浏览者看到的是网页的整体外观,前端开发 ...
- smarty类与对象的赋值与使用
<?phprequire_once('../smarty/Smarty.class.php'); //配置信息$smarty=new Smarty(); $smarty->left_del ...
- 【转载】MySQL常用系统表大全
转载地址:http://blog.csdn.net/xlxxcc/article/details/51754524 MySQL5.7 默认的模式有:information_schema, 具有 61个 ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- 练习题。对DOM中document的深刻理解巩固
//window.onload = modTwo; 1.点击单元格内容 弹窗promrt接收值 将接受的值提换单元格内容 2.点击单元格 出现2个按钮 加粗 字体颜色标红 ...
- Understanding sun.misc.Unsafe
转自: https://dzone.com/articles/understanding-sunmiscunsafe The biggest competitor to the Java virtua ...
- 淘宝IP地址库
淘宝官方ip地址库 http://ip.taobao.com/ 接口说明 1. 请求接口(GET): http://ip.taobao.com/service/getIpInfo.php?ip=[ip ...
- Linux Crontab 任务管理工具命令以及示例
Crontab 是 Linux 平台下的一款用于循环执行例行任务的工具,Linux 系统由 cron (crond) 这个系统服务来控制任务 , Linux系统本来就有很多的计划任务需要启动 , 所以 ...