随机函数的头文件是什么?

mitnick1964 2005-08-19 01:30:19
随机函数的头文件是什么?
...全文
884 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
syhan 2005-08-19
  • 打赏
  • 举报
回复
回复人: OMA_yudy(太平洋深深) ( ) 信誉:100 2005-08-19 13:50:00 得分: 0


look:

Generates a pseudorandom number.

int rand( void );
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.

Requirements
Routine Required header Compatibility
rand <stdlib.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example
// crt_rand.c
/* This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}
Sample Output
19430
28222
9710
12070
7513
9501
1767
26041
11872
4097
See Also
Floating-Point Support Routines | srand | Run-Time Routines and .NET Framework Equivalents





这个该是一个完整的随机函数的定义
我也记得是依赖于时间函数的才可以做到真正的随机
xiaocai0001 2005-08-19
  • 打赏
  • 举报
回复
<stdlib.h>
OMA_yudy 2005-08-19
  • 打赏
  • 举报
回复
look:

Generates a pseudorandom number.

int rand( void );
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.

Requirements
Routine Required header Compatibility
rand <stdlib.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example
// crt_rand.c
/* This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}
Sample Output
19430
28222
9710
12070
7513
9501
1767
26041
11872
4097
See Also
Floating-Point Support Routines | srand | Run-Time Routines and .NET Framework Equivalents


mitnick1964 2005-08-19
  • 打赏
  • 举报
回复
俺没有分了,就不要难为俺了
HaoyuTan 2005-08-19
  • 打赏
  • 举报
回复
不厚道,没分....

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧