int rand()
{
next=next*1103515245+12345;
return (unsigned int)(next/65536)%32768;
}
void srand(unsighed int seed)
{
next=seed;
}前面写了2个随机函数
利用那2个随机函数,每次键入一个值,都可以得到不同的随机数
但是,c还有一个自动获取不断变化的值来初始化种子值的函数
tinme()
基本思路:
#inlcude
srand((unsigned int)time(0))
#include //指定骰子的面数
int rollem(int sides)
{
int roll;
roll=rand()%sides+1;
}
int roll_n_dice(int dice,int sides) //加入投掷的骰子数dice
投掷骰子的程序:
1.dicerool.h 头文件 包含函数原型声明和一个extern变量声明(提醒)
2.dicerool.c 接口文件
3.manydice.c 实现接口的文件
随机函数
猜你喜欢
转载自blog.csdn.net/holiday19950913/article/details/71773748
今日推荐
周排行