亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mersennetwisterclass.html

?? A Mersenne Twister Class
?? HTML
字號:
<!--------------------------------------------------------------------------->  
<!--                           INTRODUCTION                                

 The Code Project article submission template (HTML version)

Using this template will help us post your article sooner. To use, just 
follow the 3 easy steps below:
 
     1. Fill in the article description details
     2. Add links to your images and downloads
     3. Include the main article text

That's all there is to it! All formatting will be done by our submission
scripts and style sheets. 

-->  
<!--------------------------------------------------------------------------->  
<!--                        IGNORE THIS SECTION                            -->
<html>
<head>
<title>The Code Project</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<Style>
BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt }
H2,H3,H4,H5 { color: #ff9900; font-weight: bold; }
H2 { font-size: 13pt; }
H3 { font-size: 12pt; }
H4 { font-size: 10pt; color: black; }
PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; }
CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }
</style>
<link rel="stylesheet" type=text/css href="http://www.codeproject.com/styles/global.css">
</head>
<body bgcolor="#FFFFFF" color=#000000>
<!--------------------------------------------------------------------------->  


<!-------------------------------     STEP 1      --------------------------->
<!--  Fill in the details (CodeProject will reformat this section for you) -->

<pre>
Title:       The Mersenne Twister in C++
Author:      Dave Loeser
Email:       dave@elysianonline.com
Environment: VC++ 6.0, WinNT, W2K, WXP
Keywords:    PRNG, Random, Mersenne Twister, Mersenne, Twister
Level:       Intermediate
Description: A C++ class that wraps up the Mersenne Twister (PRNG).
Section      C++ / MFC
SubSection   General
</pre>

<hr width=100% noshade>

<!-------------------------------     STEP 2      --------------------------->
<!--  Include download and sample image information.                       --> 

<ul class=download>
<li><a href="Article_demo.zip">Download demo project - XXX Kb </a></li>
<li><a href="Article_src.zip">Download source - XXX Kb</a></li>
</ul>

<p><img src="Article.gif" alt="Sample Image" width=100 height=100></p>


<!-------------------------------     STEP 3      --------------------------->
<!--  Add the article text. Please use simple formatting (<h2>, <p> etc)   --> 
<h2>Introduction</h2>
<p>The Mersenne Twister(MT) is a pseudorandom number generator (PRNG) developed by Makoto Matsumoto 
and Takuji Nishimura[1][2] during 1996-1997. MT has the following merits:  
<UL>
<LI>It is designed with consideration on the flaws of various existing generators.</LI> 
<LI>Far longer period and far higher order of equidistribution than any other implemented generators. 
(It has been proven that the period is 2^19937-1, and 623-dimensional equidistribution property is assured.)</LI>
<LI>Fast generation. (Although it depends on the system, it is reported that MT is sometimes faster 
than the standard ANSI-C library in a system with pipeline and cache memory.)</LI>
<LI>Efficient use of the memory. <!--(The implemented C-code mt19937.c consumes only 624 words of working area.)--></LI>
</UL>
<h3>Credit where it's due</h3>
I present a C++ class (<code>CRandomMT</code>) that encapsulates the work of the creators. I do not take credit
for their work, I am merely presenting an object oriented (OO) version of their code that you can simply drop 
into your game or application.
</p>

<p>
<h2>CRandomMT</h2>
<h3>Inspiration</h3>
In 2000 I was working on a random dungeon generator for a Roguelike and I asked the folks on  
<A HREF="news://rec.games.roguelike.development">rec.games.roguelike.development</A> what they 
used for PRNG. One response (or maybe two) suggested that I give the MT a try. After reading 
about its merits (see above) I decided to download it and drop it in my Roguelike. I was 
surprised that I could not find an object oriented (OO) version of the algorithm and immediately 
sat down to <i>wrap</i> the code. I mean, that is what us C++ guys do... right?
</p>
<p>
<h3>Perspiration</h3>
Wrapping the code up wasn't all that difficult and there really wasn't any perspiration, which 
made me wonder even more why the algorithm had not been encapsulated into a C++ class and made publicly 
available.  Nevertheless, I went about the business of pulling this function here and that one there 
and this one should be private, you know the drill, until I had a completely encapsulated version 
ready for use.
</p><p>
Roguelikes tend to need a good deal of random numbers so, my next task was to add a few methods 
that would make my Roguelike easier to code and the intentions of the code easy to read.  The 
standard nomenclature for representing dice rolls is: <br><b>&lt;number of dice&gt;d&lt;size of die&gt;</b>
so, to roll 2 six sided dice you would write <b>2d6</b>.  Thinking about this for a bit I determined that 
the standard nomenclature would be difficult to translate into methods for my class but if I reverse the 
nomenclature to read: <br> <b>d&lt;size of die&gt;&lt;number of dice&gt;</b> I could easily create methods
that described the intentions of the code by creating methods such as <code>CRandomMT::D6(int _DiceCount)</code>
and <code>CRandomMT::D25(int _DiceCount)</code>. Ironically, these were merely wrappers around the method: 
<code>CRandomMT::RollDice(int _DieSize, int _DiceCount)</code>.
</p>
<p>
<h3>Completion</h3>
Ahhh, completion... that really is the hardest part.  I did complete the class that I present to you and I even
completed this article. But, I failed to complete the Roguelike.  Like everything that I have burned to CD, I 
suppose that I will get around to completing that work someday.  I mean, that is what us C++ guys do... right?
</p>
<!--
<pre>
//
// Any source code blocks look like this
//
</pre>

<p>More article text...</p>
-->
<h2>Class Description</h2>
<p>
I should first point out that many of the methods are unneccessary for general use and that they are all inline.
Because this was a game and I was going to need a ton of random numbers I opted for speed over size.</p>

<p>
<code>CRandomMT::CRandomMT()</code><br>
This is the default CTOR.</p>

<p>
<code>CRandomMT::CRandomMT(ULONG seed)</code><br>
A constructor that you provide the seed value.</p>

<p>
<code>CRandomMT::~CRandomMT()</code><br>
The DTOR.</p>

<p>
<code>CRandomMT::SeedMT()</code><br>
Used to seed or re-seed the random number generator.</p>


<p>
<code>ULONG CRandomMT::RandomMT()</code><br>
Returns a unsigned long random number.</p>

<p>
<code>int CRandomMT::RandomRange(int hi, int lo)</code><br>
Returns an int random number falling in the range specified.</p>

<p>
<code>int RollDice(int face, int number_of_dice)</code><br>
Returns an int random number for the number of dice specified and the face of the die.</p>

<p>
<code>int CRandomMT::D<i>#</i>(int die_count)</code><br>
Returns a simulated roll of the number of dice specified for the die (determined by #). These
are just wrappers around <code>RollDice()</code></p>

<p>
<code>int CRandomMT::HeadsOrTails()</code><br>
Returns 0 or 1, used to simulate a coin flip.</p>

<h2>Example Usage</h2>
<pre>
#include "Random.h"	
	.
	.
	.
	CRandomMT MTrand(GetTickCount());
	int rand_3d6 = MTrand.D6(3);		// roll 3 six sided die
	.
	.
	.
</pre>

<h2>About the demo application</h2>
<p>
The demo application is a fairly lame example but does demonstrate the equidistribution provided from the MT 
algorithm as well as the speed increase.  Although I didn't percieve better distribution from the algorithm,
the speed increase is significant witht the random routine being placed inline.  Here we simulate flipping 
100,000 coins and then visualy display the results with a <code>CProgressCtrl</code> and a couple static controls 
for the textual display.  
</p>
<div align=center>
<B>NuMega TrueTime Statistics</B> *<br>
CRandomMT::RandomMT() not inlined
<TABLE BORDER=1 WIDTH=580>
<TR><TH>Function</TH><TH>% in function</TH><TH>Called</TH><TH>Avgerage</TH><TR>
<TR><TD>rand()</TD><TD>23.88</TD><TD>100,000</TD><TD>0.73</TD></TR>
<TR><TD>FlipRand()</TD><TD>13.76</TD><TD>1</TD><TD>41,864.76</TD></TR>
<TR><TD>CRandomMT::RandomMT()</TD><TD>19.83</TD><TD>100,000</TD><TD>0.60</TD></TR>
<TR><TD>FlipMersenne()</TD><TD>13.60</TD><TD>1</TD><TD>41,378.81</TD></TR>
</TABLE>
</div>
<br>
<div align=center>
<B>NuMega TrueTime Statistics</B> *<br>
CRandomMT::RandomMT() inlined
<TABLE BORDER=1 WIDTH=580>
<TR><TH>Function</TH><TH>% in function</TH><TH>Called</TH><TH>Avgerage</TH><TR>
<TR><TD>rand()</TD><TD>31.76</TD><TD>100,000</TD><TD>0.72</TD></TR>
<TR><TD>FlipRand()</TD><TD>18.22</TD><TD>1</TD><TD>41,507.23</TD></TR>
<TR><TD>CRandomMT::RandomMT()</TD><TD COLSPAN=3>INLINED</TD></TR>
<TR><TD>FlipMersenne()</TD><TD>10.88</TD><TD>1</TD><TD>26,168.42</TD></TR>
</TABLE>
</div>

<UL><B>*</B>
<LI><b>% in function</b>: Time spent on this line and the functions it called as a percentage of the time spent in the entire function.</LI>
<LI><b>Called</b>: Number of times the function was called.</LI>
<LI><b>Average</b>: Average execution time of the function during the session.</LI>
</UL>
<h3>Faster?</h3>
<p>					
In the speed category it is clear that the MT algorithm is much faster. 
The difference is that <code>FlipMersenne()</code> in the inlined version averaged 26,168.42 -vs- the 
41,507.23 of <code>FlipRand()</code> that is around a 45% increase in speed. This can be important 
in a game that needs to serve up tons of random numbers. Even the smaller increase in speed found in 
the non-inlined version results in big processor savings for applications that need to generate billions 
of random numbers.
<p>

<h3>Equidistribution?</h3>
<p>
The probability of a coin flip being heads or tails is expressed using the the mathmatical formula 
<tt>1/n</tt>. Where n is the number of times the coin is tossed.  In the demo application, we simulated
flipping the coin 100,000 times. To my surprise <code>rand()</code> provided very good results based on a 
50/50 assumption.
</p>
<p>
I started the application and brought up Excel, next I simulated flipping 100,000 coins 10 times and 
then I averaged the results from each of those iterations.  Here are the results:
</p>
<div ALIGN=center>
<B>Mersenne Twister</B>
<TABLE BORDER=1 WIDTH=580>
<TR><TD><B>FLIP(s)</B></TD><TD>1</TD><TD>2</TD><TD>3</TD><TD>4</TD><TD>5</TD><TD>6</TD><TD>7</TD><TD>8</TD><TD>9</TD><TD>10</TD><TD><B>AVG %</B></TD></TR>
<TR><TD><B>HEADS</B></TD><TD>50006</TD><TD>49910</TD><TD>49883</TD><TD>49673</TD><TD>49962</TD><TD>50073</TD><TD>49965</TD><TD>49768</TD><TD>50105</TD><TD>50116</TD><TD><B>49.946</B></TD></TR>
<TR><TD><B>TAILS</B></TD><TD>49994</TD><TD>50090</TD><TD>50117</TD><TD>50327</TD><TD>50038</TD><TD>49927</TD><TD>50035</TD><TD>50232</TD><TD>49895</TD><TD>49884</TD><TD><B>50.054</B></TD></TR>
</TABLE>
</div>

<div ALIGN=center>
<B>rand()</B>
<TABLE BORDER=1 WIDTH=580>
<TR><TD><B>FLIP(s)</B></TD><TD>1</TD><TD>2</TD><TD>3</TD><TD>4</TD><TD>5</TD><TD>6</TD><TD>7</TD><TD>8</TD><TD>9</TD><TD>10</TD><TD><B>AVG %</B></TD></TR>
<TR><TD><B>HEADS</B></TD><TD>49998</TD><TD>50091</TD><TD>49907</TD><TD>50106</TD><TD>50144</TD><TD>50097</TD><TD>49919</TD><TD>49888</TD><TD>50073</TD><TD>49847</TD><TD><B>50.007</B></TD></TR>
<TR><TD><B>TAILS</B></TD><TD>50002</TD><TD>49909</TD><TD>50093</TD><TD>49894</TD><TD>49856</TD><TD>49903</TD><TD>50081</TD><TD>50112</TD><TD>49927</TD><TD>50153</TD><TD><B>49.993</B></TD></TR>
</TABLE>
</div>
<p>
The above results for <code>rand()</code>appear to come closer to the desired 50/50 distribution of a coin 
flip than that of MT. When one adds even a small error percentage to this statistical sample, it becomes 
clear that this test is more a wash than anything else.  This leaves us with only speed as the determining 
factor in the decision to use the MT algorithim.
</p>

<h2>Conclussion</h2>
The pursuit of the perfect PRNG is an ongoing effort that eludes computer scientist and mathematicians alike.  
The Mersenne Twister is generally considered to be fast, small and provides equal distribution.  I like the
fact that I can generate 1,000,000,000 random numbers in about 0.45 seconds on a PIII 900mhz machine (with an urolled loop).


<h2>Thanks</h2>
Thanks go out to Makoto Matsumoto and Takuji Nishimura for creating the algorithm. I'd also like to thank my friend and business partner Derek Licciardi for his input and expertise in statistical analysis.


<h2>References</h2>
<UL>
	<LI>[1] "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator", M. Matsumoto and T. Nishimura, ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3--30.</LI>
	<LI><A HREF="http://www.math.keio.ac.jp/~matumoto/emt.html">[2] Mersenne Twister: A random number generator</A>, www.math.keio.ac.jp/~matumoto/emt.html</LI>
<h2>Links</h2>
	<LI><A HREF="http://www.compuware.com">Compuware Corporation</A> The makers of TrueTime
</UL>


</UL>
<!-------------------------------    That's it!   --------------------------->
</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人成影院在线观看| 国产精品久久久久久久午夜片| 色婷婷亚洲婷婷| 99re视频这里只有精品| aaa国产一区| 日本高清不卡在线观看| 91成人网在线| 欧美日本在线播放| 欧美精品一卡两卡| 日韩免费视频一区| 久久这里只有精品6| 中文字幕欧美日韩一区| 亚洲天天做日日做天天谢日日欢| 一区二区三区不卡视频| 香蕉久久一区二区不卡无毒影院 | 国产精品欧美久久久久无广告| 国产欧美日韩在线视频| 亚洲日本护士毛茸茸| 亚洲动漫第一页| 国产在线一区观看| av电影在线观看完整版一区二区| 色香蕉久久蜜桃| 91精品国产品国语在线不卡| 国产午夜精品美女毛片视频| 一区二区三区精品| 久久99精品网久久| 91在线视频18| 日韩精品一区二区三区蜜臀 | 国产精品久久久久久久久免费桃花 | 91精品国产全国免费观看| 亚洲精品在线网站| 日韩美女视频一区二区| 久久99精品国产麻豆不卡| 99国产精品久久久久| 欧美大片拔萝卜| 亚洲国产精品ⅴa在线观看| 亚洲国产成人av好男人在线观看| 国产一区二区三区不卡在线观看| 色综合久久综合| 久久综合999| 亚洲电影一级黄| 成人高清av在线| 欧美不卡在线视频| 亚洲自拍另类综合| 懂色av一区二区三区免费观看| 欧美一区二区在线看| 亚洲精品视频在线| 国产精品538一区二区在线| 欧美日本在线观看| 亚洲女人****多毛耸耸8| 国产一区二区三区免费看| 在线不卡中文字幕播放| 综合av第一页| 成人av中文字幕| 久久综合资源网| 精东粉嫩av免费一区二区三区| 欧美影院午夜播放| 亚洲人成影院在线观看| 成人网在线免费视频| www国产精品av| 久久99日本精品| 欧美一区二区免费视频| 亚洲一区二区在线观看视频| 91在线观看免费视频| 国产精品久久久久久福利一牛影视 | 亚洲国产精品一区二区久久| 91猫先生在线| 中文字幕一区二区三区四区不卡| 国产中文字幕精品| 久久婷婷一区二区三区| 国产综合久久久久久鬼色| 日韩欧美电影在线| 狠狠狠色丁香婷婷综合激情| 欧美精品一区二区三区蜜臀| 狠狠色丁香婷综合久久| 久久久99免费| 懂色av一区二区夜夜嗨| 国产精品久久久久久久久图文区| 成人永久aaa| 综合色中文字幕| 99re在线精品| 亚洲国产成人av| 欧美一区二区福利视频| 久久成人久久爱| 国产色爱av资源综合区| 国产精品99久| 亚洲伦理在线精品| 欧美三级三级三级爽爽爽| 琪琪久久久久日韩精品| 久久综合成人精品亚洲另类欧美| 成人激情免费网站| 一区二区高清免费观看影视大全| 欧美日韩一区国产| 久久精品国产亚洲a| 国产精品视频第一区| 在线观看免费亚洲| 蜜乳av一区二区三区| 亚洲国产精华液网站w| 在线观看日产精品| 激情综合网av| 一区二区三区欧美| 精品日韩欧美在线| 91欧美一区二区| 久久国产精品99精品国产| 亚洲欧美一区二区在线观看| 日韩一区二区精品在线观看| 成人黄色一级视频| 蜜桃久久av一区| 亚洲欧美在线高清| 欧美精品一区二区三区蜜桃视频| av亚洲精华国产精华| 麻豆一区二区三| 亚洲欧美日韩国产手机在线| 精品国产乱码久久久久久浪潮| 91丨九色丨蝌蚪丨老版| 日本不卡一区二区| 一区二区在线观看免费 | 99久久精品国产麻豆演员表| 午夜精品久久久久久久99水蜜桃| 国产亚洲视频系列| 777亚洲妇女| 色94色欧美sute亚洲线路一ni| 国产一区二区在线观看视频| 婷婷丁香激情综合| 一区二区三区在线免费播放| 久久久国产综合精品女国产盗摄| 欧美日韩免费在线视频| 本田岬高潮一区二区三区| 九色porny丨国产精品| 午夜久久久影院| 亚洲人成伊人成综合网小说| 亚洲国产精品成人综合 | 99久久伊人网影院| 极品美女销魂一区二区三区| 日韩av一级片| 午夜欧美电影在线观看| 亚洲一区二区不卡免费| 亚洲少妇最新在线视频| 中文字幕在线观看不卡| 日本一区二区成人在线| 国产欧美精品国产国产专区 | 欧美一级一区二区| 欧美日韩国产另类一区| 欧美中文一区二区三区| 色美美综合视频| 在线日韩一区二区| 91高清视频免费看| 欧美亚洲综合一区| 欧美怡红院视频| 在线成人av影院| 日韩欧美第一区| 久久久久久久久久久99999| 欧美精品一区二区久久久| 精品国产乱码久久久久久图片| 欧美电影免费观看高清完整版在线| 51精品久久久久久久蜜臀| 日韩一区二区免费在线电影| 日韩欧美你懂的| 久久精品人人做人人综合 | 欧美不卡一区二区三区四区| 欧美电视剧免费全集观看 | av亚洲精华国产精华精华| av福利精品导航| 欧美色大人视频| 欧美一区在线视频| 久久久不卡网国产精品一区| 国产精品久久一级| 亚洲精品免费在线播放| 亚洲成av人片| 国产专区综合网| 91视频免费看| 91精品在线观看入口| 精品国产乱码久久久久久免费| 国产欧美日韩久久| 一级女性全黄久久生活片免费| 日本三级亚洲精品| 懂色av一区二区在线播放| 欧美综合一区二区| 日韩免费视频一区二区| 国产精品第四页| 五月综合激情日本mⅴ| 国产一区二区三区精品视频| 91丝袜呻吟高潮美腿白嫩在线观看| 欧美日韩国产成人在线免费| 久久欧美中文字幕| 一区二区激情视频| 国产九色sp调教91| 欧美中文字幕一区二区三区亚洲| 欧美大白屁股肥臀xxxxxx| 成人免费一区二区三区在线观看| 日韩福利电影在线| 成人ar影院免费观看视频| 欧美疯狂做受xxxx富婆| 最新日韩av在线| 国产一区二区三区香蕉| 欧美性大战xxxxx久久久| 久久综合久久综合亚洲| 午夜久久久影院| 色呦呦日韩精品| 欧美国产丝袜视频|