⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 die.c

📁 C和指针非常好的一本书.里面的有许多代码可以借鉴.
💻 C
字号:
/*
** Simulate the throwing of a six-sided die by returning a
** random number in the range one through six.
*/
#include <stdlib.h>
#include <stdio.h>

/*
**	Compute the largest number returned by the random number
**	generator that will produce a six as the value of the die.
*/
#define	MAX_OK_RAND	\
	    (int)( ( ( (long)RAND_MAX + 1 ) / 6 ) * 6 - 1 )

int
throw_die( void ){
	static	int	is_seeded = 0;
	int	value;

	if( !is_seeded ){
		is_seeded = 1;
		srand( (unsigned int)time( NULL ) );
	}

	do {
		value = rand();
	} while( value > MAX_OK_RAND );

	return value % 6 + 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -