歡迎來到天天文庫
瀏覽記錄
ID:26791914
大?。?012.16 KB
頁數(shù):58頁
時間:2018-11-29
《蔡文能 cc++ 程式設(shè)計(jì)》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Games,RandomNumbersandIntroductiontosimplestatisticsPRNGPseudoRandomNumberGenerator蔡文能tsaiwn@csie.nctu.edu.tw蔡文能C/C++程式設(shè)計(jì)1AgendaWhatisrandomnumber(亂數(shù))?Howtherandomnumbersgenerated?rand()inClanguages:LinearCongruentialWhycall“Pseudorandom”?(P不發(fā)音)Howtodo“truerandom”?ApplicationofRrandomnum
2、ber?OthertopicsrelatedtoRandomnumbersIntroductiontosimplestatistics(統(tǒng)計(jì)簡介)蔡文能C/C++程式設(shè)計(jì)2BATNUMgamehttp://www.atariarchives.org/basicgames/showpage.php?page=14AnancientgameoftwoplayersOnepileofmatchsticks(orstones)Takesturntoremove[1,maxTake](至少拿1,至多拿maxTake)可規(guī)定拿到最後一個贏或輸!Winningstrategy??Ga
3、mes須用到RandomNumber!Why?蔡文能C/C++程式設(shè)計(jì)3BullsandCowsGamehttp://5ko.free.fr/en/bk.htmlhttp://en.wikipedia.org/wiki/Bulls_and_cowshttp://zh.wikipedia.org/zh-hant/%E7%8C%9C%E6%95%B0%E5%AD%97http://boardgames.about.com/od/paperpencil/a/bulls_and_cows.htmhttp://pyva.net/eng/play/bk.htmlhttp://www
4、.bullscows.com/index.phphttp://www.funmin.com/online-games/bulls-and-cows/index.phpGames須用到RandomNumber!Why?蔡文能C/C++程式設(shè)計(jì)4NIMGamehttp://en.wikipedia.org/wiki/NimNimisatwo-playermathematicalgameofstrategyinwhichplayerstaketurnsremovingobjectsfromdistinctheaps.Oneachturn,aplayermustremoveat
5、leastoneobject,andmayremoveanynumberofobjectsprovidedtheyallcomefromthesameheap.可規(guī)定拿到最後一個贏或輸!Winningstrategy??Games須用到RandomNumber!Why?蔡文能C/C++程式設(shè)計(jì)5Whatisrandomnumber?Sequenceofindependentrandomnumberswithaspecifieddistributionsuchasuniformdistribution(equallyprobable)Actually,thesequenc
6、egeneratedisnotrandom,butitappearstobe.SequencesgeneratedinadeterministicwayareusuallycalledPseudo-Randomsequences.參考http://www.gnu.org/software/gsl/manual/gsl-ref_19.htmlNormaldistribution?exponential,gamma,Poisson,…蔡文能C/C++程式設(shè)計(jì)6TurboC++的rand()與srand()#defineRAND_MAX0x7fffustaticunsigne
7、dlongseed=0;intrand(){seed=seed*1103515245+12345;returnseed%(RAND_MAX+1);}voidsrand(intnewseed){seed=newseed;}staticglobal變數(shù)請參考K&R課本4.6節(jié)Pseudorandomnumber就是15個1的binary注意C語言的rand()生出的不是NormalDistribution!static使其它file裡的function看不見這seed蔡文能C/C++程式設(shè)計(jì)7Unix上gcc的rand()
此文檔下載收益歸作者所有