C++中的随机数问题?

来源:百度知道 编辑:UC知道 时间:2024/07/07 10:22:56
请问怎样在C++中产生一个随机数?
srand(100)是什么意思?
rand()又是什么意思?它们在哪个头文件中啊?

srand(100)是产生0~100(不包括100)之间的随机数;
包含在<stdlib.h>中;
RAND()是产生任意的随机数

====================
在stdlib.h里面
====================
rand
Generates a pseudorandom number.

int rand( void );

Routine Required Header Compatibility
rand <stdlib.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

rand returns a pseudorandom number, as described above. There is no error return.

Remarks

The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand.

Example

/* RAND.C: Thi