如何在vc ++中生成一个随机数? [英] How to generate a random number in vc++?

查看:137
本文介绍了如何在vc ++中生成一个随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何生成随机数?我正在开发屏幕捕获项目,我想在随机的时间间隔内进行屏幕截图.因此需要一个可以从1到20中选择一个随机数的随机变量?帮帮我..

How to generate a random number? I am developing the screen capture project, I want to take the screen shots in the random interval of time. So need a random variable which can choose a random number from 1 to 20?? help me..

推荐答案

尝试一下,
Try this,
srand( (unsigned)time( NULL ) );
int nRand = rand() % 20;



该代码将生成20以下的随机数;



This code will generate random number below 20;


使用 rand [ ^ ]函数-一个简单的Google会为您找到的!
Use the rand[^] function - a simple Google would have found it for you!


这篇关于如何在vc ++中生成一个随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆