本文介紹了某個范圍內的隨機數 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++的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!