c語言隨機數(shù)函數(shù)示例
void srand( unsigned int seed );
head file is <stdlib.h>
Remarks
The 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.
#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());
}
相關(guān)文章
C語言時間函數(shù)之mktime和difftime詳解
這篇文章主要為大家詳細介紹了C語言時間函數(shù)之mktime和difftime,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一,希望能夠給你帶來幫助2022-02-02
c++?error:crosses?initialization?of問題解決分析
這篇文章主要介紹了c++?error:crosses?initialization?ofde?問題解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08
C語言中isdigit()函數(shù)和isxdigit()函數(shù)的用法
這篇文章主要介紹了C語言中isdigit()函數(shù)和isxdigit()函數(shù)的用法,用來判斷字符師傅為阿拉伯數(shù)字和16進制數(shù)字,需要的朋友可以參考下2015-08-08
C語言詳解結(jié)構(gòu)體的內(nèi)存對齊與大小計算
C 數(shù)組允許定義可存儲相同類型數(shù)據(jù)項的變量,結(jié)構(gòu)是 C 編程中另一種用戶自定義的可用的數(shù)據(jù)類型,它允許你存儲不同類型的數(shù)據(jù)項,本篇讓我們來了解C 的結(jié)構(gòu)體內(nèi)存對齊與計算大小2022-04-04

