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)文章
C語(yǔ)言實(shí)現(xiàn)飛機(jī)票務(wù)系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)飛機(jī)票務(wù)系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12C++基礎(chǔ)入門(mén)教程(二):數(shù)據(jù)、變量、宏等
這篇文章主要介紹了C++基礎(chǔ)入門(mén)教程(二):數(shù)據(jù)、變量、宏等,本文講解了變量初始化、宏定義、三種進(jìn)制數(shù)的表示、const初探、auto聲明等內(nèi)容,需要的朋友可以參考下2014-11-11C/C++實(shí)現(xiàn)動(dòng)態(tài)庫(kù)動(dòng)態(tài)加載
在很多項(xiàng)目中,我們多少會(huì)用到第三方動(dòng)態(tài)庫(kù),這些動(dòng)態(tài)庫(kù)一般都是相對(duì)固定,使用也很簡(jiǎn)單,下面我們就來(lái)看看c/c++中如何實(shí)現(xiàn)動(dòng)態(tài)庫(kù)動(dòng)態(tài)加載吧2024-01-01C++中opencv4.1.0環(huán)境配置的詳細(xì)過(guò)程
這篇文章主要介紹了C++中opencv4.1.0環(huán)境配置的詳細(xì)過(guò)程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-10-10C++面試八股文之std::string實(shí)現(xiàn)方法
這篇文章主要介紹了C++面試八股文:std::string是如何實(shí)現(xiàn)的,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-06-06C語(yǔ)言動(dòng)態(tài)與靜態(tài)分別實(shí)現(xiàn)通訊錄詳細(xì)過(guò)程
這篇文章主要為大家介紹了C語(yǔ)言動(dòng)態(tài)與靜態(tài)分別實(shí)現(xiàn)通訊錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-02-02Java C++ 題解leetcode857雇傭K名工人最低成本vector pair
這篇文章主要為大家介紹了Java C++ 題解leetcode857雇傭K名工人最低成本vector pair示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09深入解析C++11?lambda表達(dá)式/包裝器/線程庫(kù)
這篇文章主要介紹了C++11?lambda表達(dá)式/包裝器/線程庫(kù)的相關(guān)知識(shí),本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05