Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rand() 小問題~

0 views
Skip to first unread message

痞子&雜碎

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
C language

rand().. 隨機取一值..

但怎樣能以電腦的時間為索引....取一亂數值

希望大家幫忙..謝謝!

--
◎ [1;31m龍 [32m貓 [33m資 [34m訊 [35m天 [36m地 [0m( [1mbbs.mgt.ncu.edu.tw [0m)
◎[ [1;33;46mlailee [0m]來自: 140.115.226.72

Azrael

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
==> lailee (" 痞子&雜碎 ") 提到:
: C language
: rand().. 隨機取一值..
: 但怎樣能以電腦的時間為索引....取一亂數值
: 希望大家幫忙..謝謝!
srans((int)time(NULL));
好像是醬子....

--
◎ [1;31m龍 [32m貓 [33m資 [34m訊 [35m天 [36m地 [0m( [1mbbs.mgt.ncu.edu.tw [0m)

◎[ [1;33;46mNoey [0m]來自: mb2.mgt.ncu.edu.tw

Paper Crane

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
※ 引述《laile...@bbs.mgt.ncu.edu.tw ( 痞子&雜碎 )》之銘言:

> C language
> rand().. 隨機取一值..
> 但怎樣能以電腦的時間為索引....取一亂數值
> 希望大家幫忙..謝謝!
randomize <STDLIB.H>

Macro that initializes random number generator

Declaration:
void randomize(void);

Remarks:
randomize initializes the random number generator with a random
value.

Because randomize is implemented as a macro that calls the time
function prototyped in TIME.H, you should include TIME.H when you use
this routine.

Return Value: None

See Also:
rand random srand

Example:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(void)
{
int i;

randomize();
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100);
return 0;
}


--
[1;36m華梵大學 [1;32m青橄欖
[1;35mEmail: HCW...@bbs.hfu.edu.tw
[0m

--
[1;34m * 來源: 華梵大學‧阿育王 BBS <203.64.33.5> telnet://bbs.hfu.edu.tw/ [m
[1;34m * 作家: ㊣ [From: bird.hfu.edu.tw] [m

...掛 居...

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
※ 引述《Noey...@bbs.mgt.ncu.edu.tw (Azrael)》之銘言:
: ==> lailee (" 痞子&雜碎 ") 提到:
: : C language
: : rand().. 隨機取一值..
: : 但怎樣能以電腦的時間為索引....取一亂數值
: : 希望大家幫忙..謝謝!
: srans((int)time(NULL));
: 好像是醬子....
srand(time(NULL));


--
※ Origin: 程式設計樂園 ◆ From: h192.s245.ts.hinet.net

0 new messages