c++隨機數

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

int main(){
        int seed = time(NULL);
        srand(seed);
        int max,min;
        cout<<"請輸入隨機數範圍,最大值/最小值: "<<endl;
        cin>>max>>min;
        int range=max-min+1;
        int r = rand()%range+min;
        cout<<r<<endl;
        return 0;
}

發佈了117 篇原創文章 · 獲贊 5 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章