极品飞车18硬盘版:C++,请问如何产生一个1-6的随机数?

来源:百度文库 编辑:高考问答 时间:2024/04/29 20:08:27
谢谢,还有好包括的库函数.

#include<time.h>
#include<math.h>
srand(time(NULL));
int a=rand()%6+1;

不明白的问我。

include<time.h>
#include<math.h>
srand(time(NULL));
int a=rand()%6+1;

不明白的问我。

我知道JAVA的
(x+1)&7!=0

c有一个库函数rand();可以试试
rand()%6+1
也可以提取系统的时间做一些运算

rand()%6+1

rand()是产生0-1的随机数的。