[已关闭问题]
从1到100循环,如果返回0则输出Heads,否则输出Tails.<br>根据概率应该输出Heads和Tails的概率基本一样啊,应该都差不多为50次才对,可是结果是却令我非常吃惊。居然是Heads 26次,Tails 74次。<br>这是为什么呢?<br><div class="cnblogs_code"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span><img src="/Images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0);">#include</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">stdio.h</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);"> 2</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">#include</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">stdlib.h</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);"> 3</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top"><br></span><span style="color: rgb(0, 128, 128);"> 4</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> flip();<br></span><span style="color: rgb(0, 128, 128);"> 5</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top"><br></span><span style="color: rgb(0, 128, 128);"> 6</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top"></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> main()<br></span><span style="color: rgb(0, 128, 128);"> 7</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedBlockStart.gif" id="Codehighlighter1_62_297_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_62_297_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_62_297_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_62_297_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedBlock.gif" id="Codehighlighter1_62_297_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_62_297_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_62_297_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_62_297_Open_Text').style.display='inline';" align="top"></span><span id="Codehighlighter1_62_297_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_62_297_Open_Text"><span style="color: rgb(0, 0, 0);">{<br></span><span style="color: rgb(0, 128, 128);"> 8</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i;<br></span><span style="color: rgb(0, 128, 128);"> 9</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> sum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">0</span><span style="color: rgb(0, 0, 0);">;<br></span><span style="color: rgb(0, 128, 128);">10</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_115_215_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_115_215_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_115_215_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_115_215_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_115_215_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_115_215_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_115_215_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_115_215_Open_Text').style.display='inline';" align="top"> </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> ( i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);"><=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">100</span><span style="color: rgb(0, 0, 0);">; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);"> )</span><span id="Codehighlighter1_115_215_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_115_215_Open_Text"><span style="color: rgb(0, 0, 0);">{<br></span><span style="color: rgb(0, 128, 128);">11</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedSubBlockStart.gif" id="Codehighlighter1_132_180_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_180_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_132_180_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_180_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedSubBlock.gif" id="Codehighlighter1_132_180_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_132_180_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_132_180_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_132_180_Open_Text').style.display='inline';" align="top"> </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> ( flip() )</span><span id="Codehighlighter1_132_180_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_132_180_Open_Text"><span style="color: rgb(0, 0, 0);">{<br></span><span style="color: rgb(0, 128, 128);">12</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> sum </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> flip();<br></span><span style="color: rgb(0, 128, 128);">13</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> printf( </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Heads\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br></span><span style="color: rgb(0, 128, 128);">14</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);">15</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);">16</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> printf( </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Tails\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> );<br></span><span style="color: rgb(0, 128, 128);">17</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"> }</span></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);">18</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> printf( </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Sum Heads: %d\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, sum );<br></span><span style="color: rgb(0, 128, 128);">19</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> printf( </span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(128, 0, 0);">Sum Tails: %d\n</span><span style="color: rgb(128, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, i </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">1</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> sum );<br></span><span style="color: rgb(0, 128, 128);">20</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</span></span><span style="color: rgb(0, 0, 0);"><br></span><span style="color: rgb(0, 128, 128);">21</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top"><br></span><span style="color: rgb(0, 128, 128);">22</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedBlockStart.gif" id="Codehighlighter1_309_332_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_332_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_309_332_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_332_Closed_Text').style.display='inline';" align="top"><img src="/Images/OutliningIndicators/ContractedBlock.gif" id="Codehighlighter1_309_332_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_309_332_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_309_332_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_309_332_Open_Text').style.display='inline';" align="top"></span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> flip()</span><span id="Codehighlighter1_309_332_Closed_Text" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255); display: none;"><img src="/images/dot.gif"></span><span id="Codehighlighter1_309_332_Open_Text"><span style="color: rgb(0, 0, 0);">{<br></span><span style="color: rgb(0, 128, 128);">23</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/InBlock.gif" align="top"> </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> rand() </span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 128);">2</span><span style="color: rgb(0, 0, 0);">;<br></span><span style="color: rgb(0, 128, 128);">24</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top">}</span></span></div><br><br>