某个范围内的随机数 c++ [英] Random number c++ in some range

查看:22
本文介绍了某个范围内的随机数 c++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
在整个范围内均匀生成随机数

我想在 C++ 中生成某个范围内的随机数,比如说我想要 25 到 63 之间的数字.

I want to generate the random number in c++ with in some range let say i want to have number between 25 and 63.

我怎么能拥有它?

推荐答案

您可以使用标准库 (TR1) 的附加功能中包含的随机功能.或者您可以使用在普通 C 中工作的相同旧技术:

You can use the random functionality included within the additions to the standard library (TR1). Or you can use the same old technique that works in plain C:

25 + ( std::rand() % ( 63 - 25 + 1 ) )

这篇关于某个范围内的随机数 c++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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