How to get random number within a range using C++ - 如何用C++获取一定范围内的随机数
2009-08-01 21:10
597 查看
void CprjGetRandomNumberWithinRangeDlg::OnBnClickedbtntest() { // TODO: Add your control notification handler code here int i; long lRandom; CString strMsg; //=========================================================================================== for(i = 0;i < 100;i++) { GetRandomNumberWithinRange(lRandom,strMsg); TRACE(_T("%d/r/n"),lRandom); } } //Defination : //bool GetRandomNumberWithinRange(long & lRandom, CString & strMsg, long lNumberMin = 1, long lNumberMax = 19); bool CprjGetRandomNumberWithinRangeDlg::GetRandomNumberWithinRange(long & lRandom, CString & strMsg, long lNumberMin, long lNumberMax) { if(lNumberMax < lNumberMin) { strMsg = _T("lNumberMax can't be less than lNumberMin"); return false; } //随机数范围 : 5 到 20(5 + (16 - 1)) 范围 lRandom = rand() % (lNumberMax - lNumberMin + 1) + lNumberMin; return true; }
相关文章推荐
- How to get random string using C++ - 用 C++ 如何获取随机字符串
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- How to get the file's icon using C++ - 用C++如何获取文件的图标
- How to get the size of file in C++ - 在C++中如何获取文件的大小
- How to access database using C++ & ADO - 如何用C++和ADO访问数据库
- 如何在C++中使用VBScript(使用Qt)--How to use VBScript in C++ (Using Qt)
- Objective-C: Get random number 获取随机数
- How to write event log(Event Viewer) using C++ - 用C++如何写事件日志(事件查看器)
- question 002: dev c++ 当中如何调整字体大小?How to get the first program with C++? c++属于什么软件?
- C++ How to avoid the enter key when using cin and getline
- <boost -04>如何判断输入文件的类型在给定范围内?how to judge whether given file's extension is within list?
- How to invoke dll using C++ - C++ 如何调用DLL - 详解
- How to show a modal dialog and modeless dialog using C++ - 如何用C++显示一个模态对话框和一个非模态对话框
- How to change the background color of form using C++ - 如何用C++改变窗体的颜色
- C#中如何获取其他进程的命令行参数 ( How to get other processes's command line argument )
- python网络编程经典好文,如何用urllib获取internet资源,HOWTO Fetch Internet Resources Using The urllib Package
- 在iPhone应用中如何使用随机数(How to Use Random Numbers in Your iPhone App)
- How to get MetaData on client side in WCF?如何在客户端获取WCF service的元数据
- the diary of how to get a random word within a file
- How to add icon for the item of ListCtrl using C++ (Mail Attachment ListCtrl) - 如何用C++为ListCtrl的Item添加图标(邮件附件ListCtrl)