?? 7-9.cpp
字號:
#include<iostream>
#include<cmath>
using namespace std;
//return a random integer in the range[0,n)
int nrand(int n)
{
if(n<=0)
throw domain_error("Argument to nrand is out of range");
if(n>RAND_MAX)
return pow(nrand(sqrt(n)),2);
else
{
const int bucket_size=RAND_MAX/n;
int r;
do
r=rand()/bucket_size;
while(r>=n);
return r;
}
}
int main()
{
for(int i=0;i<10;++i)
cout<<nrand(32768000)<<endl;
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -