Random number c++ in some range(某个范围内的随机数 c++)
本文介绍了某个范围内的随机数 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++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:某个范围内的随机数 c++


猜你喜欢
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01