欢迎来到天天文库
浏览记录
ID:26791914
大小:1012.16 KB
页数:58页
时间:2018-11-29
《蔡文能 cc++ 程式設計》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Games,RandomNumbersandIntroductiontosimplestatisticsPRNGPseudoRandomNumberGenerator蔡文能tsaiwn@csie.nctu.edu.tw蔡文能C/C++程式設計1AgendaWhatisrandomnumber(亂數)?Howtherandomnumbersgenerated?rand()inClanguages:LinearCongruentialWhycall“Pseudorandom”?(P不發音)Howtodo“truerandom”?ApplicationofRrandomnum
2、ber?OthertopicsrelatedtoRandomnumbersIntroductiontosimplestatistics(統計簡介)蔡文能C/C++程式設計2BATNUMgamehttp://www.atariarchives.org/basicgames/showpage.php?page=14AnancientgameoftwoplayersOnepileofmatchsticks(orstones)Takesturntoremove[1,maxTake](至少拿1,至多拿maxTake)可規定拿到最後一個贏或輸!Winningstrategy??Ga
3、mes須用到RandomNumber!Why?蔡文能C/C++程式設計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++程式設計4NIMGamehttp://en.wikipedia.org/wiki/NimNimisatwo-playermathematicalgameofstrategyinwhichplayerstaketurnsremovingobjectsfromdistinctheaps.Oneachturn,aplayermustremoveat
5、leastoneobject,andmayremoveanynumberofobjectsprovidedtheyallcomefromthesameheap.可規定拿到最後一個贏或輸!Winningstrategy??Games須用到RandomNumber!Why?蔡文能C/C++程式設計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++程式設計6TurboC++的rand()與srand()#defineRAND_MAX0x7fffustaticunsigne
7、dlongseed=0;intrand(){seed=seed*1103515245+12345;returnseed%(RAND_MAX+1);}voidsrand(intnewseed){seed=newseed;}staticglobal變數請參考K&R課本4.6節Pseudorandomnumber就是15個1的binary注意C語言的rand()生出的不是NormalDistribution!static使其它file裡的function看不見這seed蔡文能C/C++程式設計7Unix上gcc的rand()
此文档下载收益归作者所有