c語(yǔ)言隨機(jī)數(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)文章
Win32應(yīng)用程序(SDK)設(shè)計(jì)原理詳解
這篇文章主要介紹了Win32應(yīng)用程序(SDK)設(shè)計(jì)原理,對(duì)于理解win32應(yīng)用程序運(yùn)行原理有很大的幫助,需要的朋友可以參考下2014-08-08
C語(yǔ)言時(shí)間函數(shù)之mktime和difftime詳解
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言時(shí)間函數(shù)之mktime和difftime,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一,希望能夠給你帶來(lái)幫助2022-02-02
C語(yǔ)言實(shí)現(xiàn)最簡(jiǎn)單的剪刀石頭布小游戲示例
這篇文章主要介紹了C語(yǔ)言實(shí)現(xiàn)最簡(jiǎn)單的剪刀石頭布小游戲,涉及C語(yǔ)言數(shù)組、隨機(jī)數(shù)與數(shù)值運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09
C語(yǔ)言解字符串逆序和單向鏈表逆序問(wèn)題的代碼示例
這篇文章主要介紹了C語(yǔ)言解字符串逆序和單向鏈表逆序問(wèn)題的代碼示例,求逆序也是考研和面試中的基礎(chǔ)算法題類(lèi)型,需要的朋友可以參考下2016-06-06
c++?error:crosses?initialization?of問(wèn)題解決分析
這篇文章主要介紹了c++?error:crosses?initialization?ofde?問(wèn)題解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
C語(yǔ)言中isdigit()函數(shù)和isxdigit()函數(shù)的用法
這篇文章主要介紹了C語(yǔ)言中isdigit()函數(shù)和isxdigit()函數(shù)的用法,用來(lái)判斷字符師傅為阿拉伯?dāng)?shù)字和16進(jìn)制數(shù)字,需要的朋友可以參考下2015-08-08
C語(yǔ)言詳解結(jié)構(gòu)體的內(nèi)存對(duì)齊與大小計(jì)算
C 數(shù)組允許定義可存儲(chǔ)相同類(lèi)型數(shù)據(jù)項(xiàng)的變量,結(jié)構(gòu)是 C 編程中另一種用戶(hù)自定義的可用的數(shù)據(jù)類(lèi)型,它允許你存儲(chǔ)不同類(lèi)型的數(shù)據(jù)項(xiàng),本篇讓我們來(lái)了解C 的結(jié)構(gòu)體內(nèi)存對(duì)齊與計(jì)算大小2022-04-04

