<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Random number generation' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Random number generation' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 06:04:17 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 06:04:17 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Random number generation</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/429783/429783/random-number-generation/</link>
      <description>I am a total newbie, and I am pretty hung up on the implementation of a random number generation into a program I am supposed to write (C++).  If I am given information about the probability of possible outcomes, how do I use a random number generator to predict the future events based on said probability figures?  &lt;br /&gt;
&lt;br /&gt;
The program is based on the next years baseball batting pcts and such.  After rereading again and again I can only assume that I use each of the possibilities that add up to 100 percent, and use each of these separately ie. the probability for a single is 20 percent, so i use if(x &amp;gt;= 1 &amp;amp;&amp;amp; x &amp;lt;=20) then blah blah blah....  Kind of stuck...  Any way someone can push me in the right direction?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/429783/429783/random-number-generation/</guid>
      <pubDate>Wed, 10 Oct 2012 21:59:56 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/429783/429789/re-random-number-generation/#429789</link>
      <description>OK so I tried to work on it a little more, can someone give me an idea as to how correct my updated code is.  i am trying to run a number generator 1000 times to get statistical probabilities for the upcoming season for a particular hitter.  AM I WAY OFF??&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdlib&amp;gt;&lt;br /&gt;
#include &amp;lt;ctime&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
&lt;br /&gt;
	double batAvg, slugPct;&lt;br /&gt;
	int atBats = 0,&lt;br /&gt;
		outs = 0, &lt;br /&gt;
		walks = 0, &lt;br /&gt;
		hits = 0, &lt;br /&gt;
		singles = 0, &lt;br /&gt;
		doubles = 0, &lt;br /&gt;
		triples = 0, &lt;br /&gt;
		homeRuns = 0,&lt;br /&gt;
		randomNum = 1 + rand() % 100;&lt;br /&gt;
	//srand(time(NULL));			// random number generator&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
					//1-100&lt;br /&gt;
	for(atBats=0; atBats &amp;lt;= 1000; atBats++)&lt;br /&gt;
&lt;br /&gt;
	hits = (singles + doubles + triples + homeRuns);&lt;br /&gt;
	batAvg = hits / (atBats - walks);&lt;br /&gt;
	slugPct = ((singles + (doubles * 2) + (triples * 3) + (homeRuns * 4)) / &lt;br /&gt;
	(atBats - walks));&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
			&lt;br /&gt;
				&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
		if(randomNum &amp;gt;= 1 &amp;amp;&amp;amp; randomNum &amp;lt;=20)&lt;br /&gt;
			singles += 1;&lt;br /&gt;
			&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 20 &amp;amp;&amp;amp; randomNum &amp;lt;= 35)&lt;br /&gt;
				doubles += 1;&lt;br /&gt;
				&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 35 &amp;amp;&amp;amp; randomNum &amp;lt;= 44)&lt;br /&gt;
				triples += 1;&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 44 &amp;amp;&amp;amp; randomNum  &amp;lt;= 49)&lt;br /&gt;
				homeRuns += 1;&lt;br /&gt;
			&lt;br /&gt;
			else if(randomNum &amp;gt; 49 &amp;amp;&amp;amp; randomNum &amp;lt;=65)&lt;br /&gt;
				walks += 1;&lt;br /&gt;
			&lt;br /&gt;
			else&lt;br /&gt;
				outs += 1;&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of singles is " &amp;lt;&amp;lt; singles &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of doubles is " &amp;lt;&amp;lt; &lt;br /&gt;
					doubles &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of triples is " &amp;lt;&amp;lt; &lt;br /&gt;
					triples &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of homeruns is " &amp;lt;&amp;lt; homeRuns &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of walks is " &amp;lt;&amp;lt; walks &amp;lt;&amp;lt; endl;&lt;br /&gt;
	&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of hits is " &amp;lt;&amp;lt; hits &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected batting average for next year is " &amp;lt;&amp;lt; batAvg &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected slugging percentage for next year is " &amp;lt;&amp;lt; slugPct &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
&lt;br /&gt;
}// end main&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/429783/429789/re-random-number-generation/#429789</guid>
      <pubDate>Thu, 11 Oct 2012 20:19:43 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: Random number generation</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/429783/429790/re-random-number-generation/#429790</link>
      <description>OK so I tried to work on it a little more, can someone give me an idea as to how correct my updated code is.  i am trying to run a number generator 1000 times to get statistical probabilities for the upcoming season for a particular hitter.  AM I WAY OFF??&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdlib&amp;gt;&lt;br /&gt;
#include &amp;lt;ctime&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
&lt;br /&gt;
	double batAvg, slugPct;&lt;br /&gt;
	int atBats = 0,&lt;br /&gt;
		outs = 0, &lt;br /&gt;
		walks = 0, &lt;br /&gt;
		hits = 0, &lt;br /&gt;
		singles = 0, &lt;br /&gt;
		doubles = 0, &lt;br /&gt;
		triples = 0, &lt;br /&gt;
		homeRuns = 0,&lt;br /&gt;
		randomNum = 1 + rand() % 100;&lt;br /&gt;
	//srand(time(NULL));			// random number generator&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
					//1-100&lt;br /&gt;
	for(atBats=0; atBats &amp;lt;= 1000; atBats++)&lt;br /&gt;
&lt;br /&gt;
	hits = (singles + doubles + triples + homeRuns);&lt;br /&gt;
	batAvg = hits / (atBats - walks);&lt;br /&gt;
	slugPct = ((singles + (doubles * 2) + (triples * 3) + (homeRuns * 4)) / &lt;br /&gt;
	(atBats - walks));&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
			&lt;br /&gt;
				&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
		if(randomNum &amp;gt;= 1 &amp;amp;&amp;amp; randomNum &amp;lt;=20)&lt;br /&gt;
			singles += 1;&lt;br /&gt;
			&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 20 &amp;amp;&amp;amp; randomNum &amp;lt;= 35)&lt;br /&gt;
				doubles += 1;&lt;br /&gt;
				&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 35 &amp;amp;&amp;amp; randomNum &amp;lt;= 44)&lt;br /&gt;
				triples += 1;&lt;br /&gt;
		&lt;br /&gt;
			else if(randomNum &amp;gt; 44 &amp;amp;&amp;amp; randomNum  &amp;lt;= 49)&lt;br /&gt;
				homeRuns += 1;&lt;br /&gt;
			&lt;br /&gt;
			else if(randomNum &amp;gt; 49 &amp;amp;&amp;amp; randomNum &amp;lt;=65)&lt;br /&gt;
				walks += 1;&lt;br /&gt;
			&lt;br /&gt;
			else&lt;br /&gt;
				outs += 1;&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of singles is " &amp;lt;&amp;lt; singles &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of doubles is " &amp;lt;&amp;lt; &lt;br /&gt;
					doubles &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of triples is " &amp;lt;&amp;lt; &lt;br /&gt;
					triples &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of homeruns is " &amp;lt;&amp;lt; homeRuns &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of walks is " &amp;lt;&amp;lt; walks &amp;lt;&amp;lt; endl;&lt;br /&gt;
	&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected number of hits is " &amp;lt;&amp;lt; hits &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected batting average for next year is " &amp;lt;&amp;lt; batAvg &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
cout &amp;lt;&amp;lt; "The projected slugging percentage for next year is " &amp;lt;&amp;lt; slugPct &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
&lt;br /&gt;
}// end main&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/beginnercpp/429783/429790/re-random-number-generation/#429790</guid>
      <pubDate>Thu, 11 Oct 2012 20:21:32 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>