????C++?е?????<cstdlib>????????<iostream>?У???????????????α????????????rand??????srand??????
???????????int rand??void????
??????srand??seed???????seed?????????????Χ????[seed??RAND_MAX??0x7fff?????????????
????????????void srand??unsigned seed????
???????seed??rand?????????????????????????rand????????????
???????????rand?????????????????????srand???????????????rand???????????ù?srand?????????seed??????????????rand ??????seed??????????α???????????????????????rand???????е??ù?srand?????????rand?????????????????srand ??1????????????1???α????????????
???????????????????????rand????????γ????????????????????????????srand??seed???е????seed?????????????????????????? ???????????????????????????????????????????????seed????????????????????γ?????е????rand???????????????????????????? ?????????[seed??RAND_MAX??0x7fff??????Χ?е??????????????
??????????????????£?????????????0~6?????????????????6???????
?????????????????seed???????
????for??int i=0??i<10??i++??
????{
????ran_num=rand????%6??
????cout<<ran_num<<“ ”??
????}
?????????г?????????????5 5 4 4 5 4 0 0 4 2
??????????????seed?1????
????srand??1????
????for??int i=0??i<10??i++??
????{
????ran_num=rand????%6??
????cout<<ran_num<<“ ”??
????}
?????????г?????????????5 5 4 4 5 4 0 0 4 2????????????????????
???????????????seed????6????
????srand??6????
????for??int i=0??i<10??i++??
????{
????ran_num=rand????%6??
????cout<<ran_num<<“ ”??
????}
?????????г??????????????4 1 5 1 4 3 4 4 2 2???????????????????????????????????????????
??????????????seed?????????????????????λ???time_t time??0????????
????#include<ctime>
????……
????srand????unsigned??time??0??????
????for??int i=0??i<10??i++??
????{
????ran_num=rand????%6??
????cout<<ran_num<<“ ”??
????}
??????г???????????????????0 1 5 4 5 0 2 3 4 2????????????3 2 3 0 3 5 5 2 2 3??... ...??ε???н?????????????????????????????????????
????????time_t time??0??
????time_t ???????????????????????1970??1??1??????????????????????????????λ????????? cout<<time(0) ??????????1169174701???????37????* 365????* 24??С???* 3600???????o?????????
????????ran_num=rand????%6
??????rand????????????6????????????????????????????????[0??6??????????????????????????????? ??RAND_MAX????32767??????????????????????[a??b???????????????????rand????%??b-a????+ a????????? a ?????? b ??