C++版:
```cpp
#include<iosream>
#include<ctime>
using namespace std;
int main(){
int n;
cin>>n;
srand(time(NULL));
int a=rand()%n+1;
cout<<a<<endl;
}
```
其他语言我不会
by RiverFun @ 2018-06-23 09:12:09
@ 司马风吟
by RiverFun @ 2018-06-23 09:13:24
@[司马风吟](/space/show?uid=93707)
by RiverFun @ 2018-06-23 09:13:31
@[Steve_braveman](/space/show?uid=96570) 不会的就是c++啊~~
谢谢dalao~~
by Rnfmabj @ 2018-06-23 09:14:03
@[Steve_braveman](/space/show?uid=96570)
对了,那限定的范围写在哪呢?
by Rnfmabj @ 2018-06-23 09:15:06
@[司马风吟](/space/show?uid=93707) 输出就行了
by Kiel @ 2018-06-23 09:21:58
@[something](/space/show?uid=84025)
嗯?
我怎么在(NULL)后面炸了?
by Rnfmabj @ 2018-06-23 09:24:13
@[司马风吟](/space/show?uid=93707) 需要`#include<cstdlib>`
by Aleph1022 @ 2018-06-23 09:25:40
假如要取$[l,r]$范围内的随机整数:
```cpp
int a=rand()%(r-l+1)+l;
```
最前面要写`srand(time(NULL));`
by 破壁人五号 @ 2018-06-23 09:26:37
@[I_love_him52](/space/show?uid=75840)
成功了...早知道用van能头文件了
by Rnfmabj @ 2018-06-23 09:26:43