srand
Sets a random starting point.void srand( unsigned int seed );Routine Required Header Compatibility
srand <stdlib.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return ValueNoneParameterseedSeed for random-number generationResThe srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.Example/* 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>void 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() );
}
Output 6929
8026
21987
30734
20587
6699
22034
25051
7988
10104
Sets a random starting point.void srand( unsigned int seed );Routine Required Header Compatibility
srand <stdlib.h> ANSI, Win 95, Win NT
For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return ValueNoneParameterseedSeed for random-number generationResThe srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.Example/* 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>void 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() );
}
Output 6929
8026
21987
30734
20587
6699
22034
25051
7988
10104
解决方案 »
- 关于SendMessage函数的小问题
- 求,USB驱动开发(C8051F320控制器)示例代码 (另开帖追加100分...............)
- 一个关于输入法生成器的问题
- 如何显示出宽度最小的"."和"-"符号
- 如何将二进制数据文件以图形的方式显示在一个对话框的控件内
- 怎样在CView创建时改变其classtype,如我想去掉CS_HREDRAW属性,急,谢谢大家!!!!
- 请问如何用 命令行 编译完成一个多动态库的项目?
- 类似VS的界面哪里有源码下载,最好有例子源码,听说有这样的类库。谢谢先。
- 搞过WINCE的同志进来,留下QQ或EMAIL吧
- ADO读取ACCESS,读不出数据。
- 关于odbc调用存储过程,好几天没解决,所以我的毕设一直在原地徘徊
- 初学VC请指教!放分!2
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.LibrariesLIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Valuerand returns a pseudorandom number, as described above. There is no error return.ResThe 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: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/#include <stdlib.h>
#include <stdio.h>
#include <time.h>void 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() );
}
Output 6929
8026
21987
30734
20587
6699
22034
25051
7988
10104
Floating-Point Support RoutinesSee Also srand
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
Example See AlsoReturns a random number between 0 and 1.SyntaxRAND([nSeedValue])ReturnsNumericArgumentsnSeedValueSpecifies the seed value that determines the sequence of values RAND( ) returns.RAND( ) returns the same sequence of random numbers if you use the same seed value for nSeedValue the first time you issue RAND( ) followed by subsequent RAND( ) function calls without nSeedValue.If nSeedValue is negative the first time you issued RAND( ), a seed value from the system clock is used. To achieve the most random sequence of numbers, issue RAND( ) initially with a negative argument and then issue RAND( ) without an argument.If you omit nSeedValue, RAND( ) uses a default seed value of 100,001.
Is it???
c and unix's run-time library??
api??!!