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