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

📄 utility.cpp

📁 VC源代码大全(精华版)
💻 CPP
字号:
//
//	utility.cpp. Some useful routines to make life easier
//
#include "stdafx.h"

void Randomize ()
{
time_t		t;
unsigned int	n;

/*
	Get the current time. That will be used to seed the random number
	function.
 */
	time (&t);

/*
	srand() requires an unsigned int, but time returns an unsigned long.
	Mask off any unused bits at the top in case there are any errors
	in typecasting (we want the lower part of the time because it should
	always be different, and sizeof (time_t) and sizeof (int) may not be
	the same on all systems).
 */
	n = (unsigned int) (t & ((long) ((unsigned int) -1)));

/*
		Now, use that value as the random number seed.
 */
	srand (n);
}

/*
	Return a random number in the range 0 to num-1. If 0 is passed, return
	it. If a negative number is passed, return the random number.
 */

int Random (int num)
{
	if (!num)
		return (0);
	if (num < 0)
		return (rand ());
	return (rand () % num);
}

⌨️ 快捷键说明

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