<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 5.9 &#8212; Random number generation</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/59-random-number-generation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: haziq</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-96710</link>
		<dc:creator>haziq</dc:creator>
		<pubDate>Wed, 21 Dec 2011 04:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-96710</guid>
		<description>Thanks. Your tutorials are always very explanatory. But you don&#039;t seem to have introduced the idea of introducing a bit true randomness using time() function or by using current date and time. I have tried the same on my blog.</description>
		<content:encoded><![CDATA[<p>Thanks. Your tutorials are always very explanatory. But you don&#8217;t seem to have introduced the idea of introducing a bit true randomness using time() function or by using current date and time. I have tried the same on my blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: primecodz</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-96510</link>
		<dc:creator>primecodz</dc:creator>
		<pubDate>Tue, 29 Nov 2011 20:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-96510</guid>
		<description>So I tried to make a random number generator between 1 and 13. And at the end when you guess correctly it shows how many times you guessed. It is funny though because it seems whenever I enter 3 into the program it comes out blank and ends the program. 

Here is the code: 
#include 
#include 
#include 


using namespace std;

int counter=0;

unsigned int getRandom(int nHigh, int nLow){
	return (rand() % (nHigh - nLow + 1)) + nLow;
}
int main(){
	int x, y;
	x=1;
	y=13;
	int nGuess;

	cout &lt;&lt; &quot;Enter a gues between 1 and 6: &quot; &lt;&gt; nGuess;
	getRandom(y,x);
	if (nGuess &lt; getRandom(y,x)){
		cout &lt;&lt; &quot;too low try again&quot; &lt; getRandom(y,x)){
		cout &lt;&lt; &quot;Too high try again&quot; &lt;&lt; endl;
		counter=counter+1;
		main();
	}
	else if (nGuess == getRandom(y,x)){
		cout &lt;&lt; &quot;Congradulations!&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Number of Guesses: &quot; &lt;&lt; counter &lt;&lt; endl;

	}
	system (&quot;PAUSE&quot;);
	return 0;
}</description>
		<content:encoded><![CDATA[<p>So I tried to make a random number generator between 1 and 13. And at the end when you guess correctly it shows how many times you guessed. It is funny though because it seems whenever I enter 3 into the program it comes out blank and ends the program. </p>
<p>Here is the code:<br />
#include<br />
#include<br />
#include </p>
<p>using namespace std;</p>
<p>int counter=0;</p>
<p>unsigned int getRandom(int nHigh, int nLow){<br />
	return (rand() % (nHigh &#8211; nLow + 1)) + nLow;<br />
}<br />
int main(){<br />
	int x, y;<br />
	x=1;<br />
	y=13;<br />
	int nGuess;</p>
<p>	cout &lt;&lt; &quot;Enter a gues between 1 and 6: &quot; &lt;&gt; nGuess;<br />
	getRandom(y,x);<br />
	if (nGuess &lt; getRandom(y,x)){<br />
		cout &lt;&lt; &quot;too low try again&quot; &lt; getRandom(y,x)){<br />
		cout &lt;&lt; &quot;Too high try again&quot; &lt;&lt; endl;<br />
		counter=counter+1;<br />
		main();<br />
	}<br />
	else if (nGuess == getRandom(y,x)){<br />
		cout &lt;&lt; &quot;Congradulations!&quot; &lt;&lt; endl;<br />
		cout &lt;&lt; &quot;Number of Guesses: &quot; &lt;&lt; counter &lt;&lt; endl;</p>
<p>	}<br />
	system (&quot;PAUSE&quot;);<br />
	return 0;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hypehuman</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95943</link>
		<dc:creator>hypehuman</dc:creator>
		<pubDate>Sun, 28 Aug 2011 18:07:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95943</guid>
		<description>Alex, your tutorial is awesome! I&#039;ve been using it for a while and having a lot of fun. I managed to make a program that intelligently plays Minesweeper because of your tutorial!

Anyway, I think this is a mistake:

&quot;Second, the method by which the next number in the sequence shouldn’t be obvious or predictable.&quot;

should be:

&quot;Second, the method by which the next number in the sequence &lt;strong&gt;is generated&lt;/strong&gt; shouldn’t be obvious or predictable.&quot;</description>
		<content:encoded><![CDATA[<p>Alex, your tutorial is awesome! I&#8217;ve been using it for a while and having a lot of fun. I managed to make a program that intelligently plays Minesweeper because of your tutorial!</p>
<p>Anyway, I think this is a mistake:</p>
<p>&#8220;Second, the method by which the next number in the sequence shouldn’t be obvious or predictable.&#8221;</p>
<p>should be:</p>
<p>&#8220;Second, the method by which the next number in the sequence <strong>is generated</strong> shouldn’t be obvious or predictable.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jupi</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95940</link>
		<dc:creator>Jupi</dc:creator>
		<pubDate>Fri, 26 Aug 2011 23:39:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95940</guid>
		<description>Nevermind, I figured it out!</description>
		<content:encoded><![CDATA[<p>Nevermind, I figured it out!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jupi</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95937</link>
		<dc:creator>Jupi</dc:creator>
		<pubDate>Thu, 25 Aug 2011 23:00:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95937</guid>
		<description>In the function:

&lt;code&gt;unsigned int GetRandomNumber(int nLow, int nHigh)
{
    return (rand() % (nHigh - nLow + 1)) + nLow;
}&lt;/code&gt;

I don&#039;t understand why those operations are being done to the random number. I also don&#039;t get how using the modulus operator can change the maximum value for a random number (as in the first example: &lt;code&gt;return nSeed  % 32767;&lt;/code&gt;). Will someone explain please?</description>
		<content:encoded><![CDATA[<p>In the function:</p>
<p><code>unsigned int GetRandomNumber(int nLow, int nHigh)<br />
{<br />
    return (rand() % (nHigh - nLow + 1)) + nLow;<br />
}</code></p>
<p>I don&#8217;t understand why those operations are being done to the random number. I also don&#8217;t get how using the modulus operator can change the maximum value for a random number (as in the first example: <code>return nSeed  % 32767;</code>). Will someone explain please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: coyote</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95634</link>
		<dc:creator>coyote</dc:creator>
		<pubDate>Sun, 26 Jun 2011 12:57:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95634</guid>
		<description>Just as a heads up, I noticed that when I ran the last program for random numbers I did get output that was as high as: 2033645517.  This is on a linux box so it might be that different systems/compilers have different defaults for the RAND_MAX constant.</description>
		<content:encoded><![CDATA[<p>Just as a heads up, I noticed that when I ran the last program for random numbers I did get output that was as high as: 2033645517.  This is on a linux box so it might be that different systems/compilers have different defaults for the RAND_MAX constant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zingmars</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95599</link>
		<dc:creator>zingmars</dc:creator>
		<pubDate>Sun, 19 Jun 2011 18:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95599</guid>
		<description>right before the return statement.</description>
		<content:encoded><![CDATA[<p>right before the return statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dragon</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95463</link>
		<dc:creator>Dragon</dc:creator>
		<pubDate>Mon, 16 May 2011 20:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95463</guid>
		<description>Where do you put the code that keeps the application up for more than a millisecond?</description>
		<content:encoded><![CDATA[<p>Where do you put the code that keeps the application up for more than a millisecond?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jonathonjones</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95419</link>
		<dc:creator>jonathonjones</dc:creator>
		<pubDate>Fri, 06 May 2011 22:26:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95419</guid>
		<description>Minor nitpick: in the examples, you have the following comment:

// If we&#039;ve printed 5 numbers, start a new column

But actually, you&#039;re starting a new row, not a new column.</description>
		<content:encoded><![CDATA[<p>Minor nitpick: in the examples, you have the following comment:</p>
<p>// If we&#8217;ve printed 5 numbers, start a new column</p>
<p>But actually, you&#8217;re starting a new row, not a new column.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhananjay</title>
		<link>http://www.learncpp.com/cpp-tutorial/59-random-number-generation/comment-page-1/#comment-95398</link>
		<dc:creator>dhananjay</dc:creator>
		<pubDate>Fri, 29 Apr 2011 10:05:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=218#comment-95398</guid>
		<description>Declare function prototype as bool check(), instead of bool check.</description>
		<content:encoded><![CDATA[<p>Declare function prototype as bool check(), instead of bool check.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

