請問這個程式中srand()與rand()如何使用? |
尚未結案
|
GEPCY
一般會員 發表:3 回覆:4 積分:1 註冊:2005-01-05 發送簡訊給我 |
/*取自吳勁華-資料結構-金禾資訊-chap3-1 stack
請各為大大幫助提供解釋
Q1:srand()
Q2:rand()
*/ #include
|
GEPCY
一般會員 發表:3 回覆:4 積分:1 註冊:2005-01-05 發送簡訊給我 |
|
fffhghgjh
一般會員 發表:2 回覆:33 積分:17 註冊:2004-12-23 發送簡訊給我 |
void srand(unsigned seed); Description Initializes random number generator. The random number generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number. 這是給random的函數一個起始點
比較多的做法會取時間帶入
用來在rand(void)中能產生不同的亂數
如果不用srand可以用randmize(void)
也是可以取不同的亂數起點
|
GEPCY
一般會員 發表:3 回覆:4 積分:1 註冊:2005-01-05 發送簡訊給我 |
|
fffhghgjh
一般會員 發表:2 回覆:33 積分:17 註冊:2004-12-23 發送簡訊給我 |
time_t time(time_t *timer); Description Gets time of day. time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970, and stores that value in the location pointed to by timer, provided that timer is not a NULL pointer. 在time的function中
需要傳一個指標過去
也可以這樣用
time_t t;
t = time(&t);
一樣會得到現在的時間
NULL是C 內定字==>
NULL #define
Description
Null pointer constant that is compatible with any data object pointer. It is not compatible with function pointers. When a pointer is equivalent to NULL it is guaranteed not to point to any data object defined within the program.
|
GEPCY
一般會員 發表:3 回覆:4 積分:1 註冊:2005-01-05 發送簡訊給我 |
|
fffhghgjh
一般會員 發表:2 回覆:33 積分:17 註冊:2004-12-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |