C/C++产生区间随机整数或小数的方法

C/C++产生区间随机整数或小数的方法

#include <iostream>
#include <queue>
#include <cstdlib>
#include <ctime>
using namespace std;
const int MIN = 0;
const int MAX = 99;
int main(){
    //priority_queue<int> q;
	priority_queue<double> q;
	srand((unsigned int)time(NULL));
    for( int i= 0; i< 1000; ++i )
		 //q.push( MIN+rand()%(MAX-MIN+1) );
		 q.push( MIN+(rand()/(double(RAND_MAX)))*(MAX-MIN) );
    while( !q.empty() ){
        cout << q.top() << endl;
        q.pop();
    }
    return 0;
}

喜欢就点个赞吧,谢谢啦

猜你喜欢

转载自blog.csdn.net/weixin_38604589/article/details/88673102