<?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/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
	>
<channel>
	<title>Comments on: AS3 Tutorial &#8211; Math.random()</title>
	<atom:link href="http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/</link>
	<description>We Make Flash Games</description>
	<lastBuildDate>Fri, 10 Feb 2012 03:01:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Hoang</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-7902</link>
		<dc:creator>Hoang</dc:creator>
		<pubDate>Thu, 21 Apr 2011 06:35:32 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-7902</guid>
		<description>Again, very clear tutorial.Love it :D
By the way, I wonder how Flash and other programming languages actually create a random number?
I&#039;ve been told that it&#039;s somewhere in computer clock (or something), but I can&#039;t either see the point or make sure if I can trust its &quot;randomness&quot;.
Can you help me make this clear?

p/s: English is not my native language so... my English is not really good :P</description>
		<content:encoded><![CDATA[<p>Again, very clear tutorial.Love it :D<br />
By the way, I wonder how Flash and other programming languages actually create a random number?<br />
I&#8217;ve been told that it&#8217;s somewhere in computer clock (or something), but I can&#8217;t either see the point or make sure if I can trust its &#8220;randomness&#8221;.<br />
Can you help me make this clear?</p>
<p>p/s: English is not my native language so&#8230; my English is not really good :P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-7779</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Tue, 29 Mar 2011 02:51:06 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-7779</guid>
		<description>Yes, but how did i GET there?  i blame Flashkit.</description>
		<content:encoded><![CDATA[<p>Yes, but how did i GET there?  i blame Flashkit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GuestCheap</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-7768</link>
		<dc:creator>GuestCheap</dc:creator>
		<pubDate>Fri, 25 Mar 2011 09:21:59 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-7768</guid>
		<description>probably the reason why this is your most popular post is because it appears first if you search &quot;Math.random as3&quot; in Google...</description>
		<content:encoded><![CDATA[<p>probably the reason why this is your most popular post is because it appears first if you search &#8220;Math.random as3&#8243; in Google&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-7402</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Wed, 02 Feb 2011 20:07:04 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-7402</guid>
		<description>Thanks, Pete!  It&#039;s funny - the A* article was actually written by one of our programmers (who&#039;s since left us) Phil Chertok.  A few months after Phil departed, i actually sat down to write some A* pathfinding and i thought &quot;oh - how convenient.  i&#039;ll just use Phil&#039;s article.&quot;  i actually had the same problem ... not simple enough.

i did find a MUCH simpler A* primer, but it was so simple that it went on for pages and pages explaining how the algorithm works.  It was a great instructional tool, but it was outside of the scope of what Phil was writing here ... after all, he had a game to program for me!

Anyway, these are the lessons i followed.  i can&#039;t recommend them enough:

&lt;a href=&quot;http://ai-depot.com/Tutorial/PathFinding.html&quot; rel=&quot;nofollow&quot;&gt;http://ai-depot.com/Tutorial/PathFinding.html&lt;/a&gt;

(oh - and thanks for the article requests!  You&#039;re the first person to take me up on that)</description>
		<content:encoded><![CDATA[<p>Thanks, Pete!  It&#8217;s funny &#8211; the A* article was actually written by one of our programmers (who&#8217;s since left us) Phil Chertok.  A few months after Phil departed, i actually sat down to write some A* pathfinding and i thought &#8220;oh &#8211; how convenient.  i&#8217;ll just use Phil&#8217;s article.&#8221;  i actually had the same problem &#8230; not simple enough.</p>
<p>i did find a MUCH simpler A* primer, but it was so simple that it went on for pages and pages explaining how the algorithm works.  It was a great instructional tool, but it was outside of the scope of what Phil was writing here &#8230; after all, he had a game to program for me!</p>
<p>Anyway, these are the lessons i followed.  i can&#8217;t recommend them enough:</p>
<p><a href="http://ai-depot.com/Tutorial/PathFinding.html" rel="nofollow">http://ai-depot.com/Tutorial/PathFinding.html</a></p>
<p>(oh &#8211; and thanks for the article requests!  You&#8217;re the first person to take me up on that)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-7390</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Tue, 01 Feb 2011 06:02:38 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-7390</guid>
		<description>I just found this blog a few days ago, and several times I&#039;ve idly returned to read bookmarks, but this is the first time I&#039;ve ventured into the comments for any of the posts.

I find myself wishing for more posts than are currently available now. =p

(like seriously, add interfaces to your oop section and the A* series needs a little more handholding!)</description>
		<content:encoded><![CDATA[<p>I just found this blog a few days ago, and several times I&#8217;ve idly returned to read bookmarks, but this is the first time I&#8217;ve ventured into the comments for any of the posts.</p>
<p>I find myself wishing for more posts than are currently available now. =p</p>
<p>(like seriously, add interfaces to your oop section and the A* series needs a little more handholding!)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6807</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Sat, 23 Oct 2010 01:32:41 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6807</guid>
		<description>Works for me.  Just open a new Flash file, paste it into the first frame&#039;s Actions, and build/run the movie.</description>
		<content:encoded><![CDATA[<p>Works for me.  Just open a new Flash file, paste it into the first frame&#8217;s Actions, and build/run the movie.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6802</link>
		<dc:creator>Jeffrey</dc:creator>
		<pubDate>Fri, 22 Oct 2010 21:36:26 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6802</guid>
		<description>I tried this I can not get it to work, can please check and make sure that all the punctuation is correct.  I was told that if you put an extra space in it may not work correctly.</description>
		<content:encoded><![CDATA[<p>I tried this I can not get it to work, can please check and make sure that all the punctuation is correct.  I was told that if you put an extra space in it may not work correctly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6799</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Fri, 22 Oct 2010 18:55:31 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6799</guid>
		<description>Hmm ... it troubles me that you spelled &quot;college&quot; incorrectly, and that you&#039;re asking me to fix code that you copy-pasted without understanding it because you were too high seven years ago to pay attention in class. 

But since i strongly believe in wasting my time to help people who aren&#039;t willing to put even a modicum of effort into their craft, here&#039;s your code:

&lt;pre lang=&quot;actionscript&quot;&gt;
var str1 : String = &quot;f&quot;;
var str2 : String = &quot;uck o&quot;;
var str3: String = &quot;ff&quot;;
for(var i:int =0; i&lt;5000; i++)
{
    trace(str1 + str2 + str3 + &quot; and die.&quot;);
}

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hmm &#8230; it troubles me that you spelled &#8220;college&#8221; incorrectly, and that you&#8217;re asking me to fix code that you copy-pasted without understanding it because you were too high seven years ago to pay attention in class. </p>
<p>But since i strongly believe in wasting my time to help people who aren&#8217;t willing to put even a modicum of effort into their craft, here&#8217;s your code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> str1 : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;f&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> str2 : <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;uck o&quot;</span>;
<span style="color: #000000; font-weight: bold;">var</span> str3: <span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;ff&quot;</span>;
<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> =<span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span><span style="color: #cc66cc;">5000</span>; i++<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>str1 + str2 + str3 + <span style="color: #ff0000;">&quot; and die.&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6798</link>
		<dc:creator>Jeffrey</dc:creator>
		<pubDate>Fri, 22 Oct 2010 18:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6798</guid>
		<description>Can spell it out, I did flash in collage 7 years ago and was not good at it, so I am digging deep to get this far.  So what would that look like.</description>
		<content:encoded><![CDATA[<p>Can spell it out, I did flash in collage 7 years ago and was not good at it, so I am digging deep to get this far.  So what would that look like.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6796</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Fri, 22 Oct 2010 17:49:42 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6796</guid>
		<description>Jeffrey - just transplant your conditional snippet so that it&#039;s inside the statement block of your loop.</description>
		<content:encoded><![CDATA[<p>Jeffrey &#8211; just transplant your conditional snippet so that it&#8217;s inside the statement block of your loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffrey</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6795</link>
		<dc:creator>Jeffrey</dc:creator>
		<pubDate>Fri, 22 Oct 2010 17:40:43 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6795</guid>
		<description>I am trying something different.  I have a number generate and it tells me the number in the output tab, however how do I call the number to my if else statement.  I have a bit of the code here:

&lt;pre lang=&quot;actionscript&quot;&gt;
function randRange(min:Number, max:Number):Number { 
    var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min; 
    return randomNum; 
} 
for (var i = 0; i &lt; 1; i++) { 
    var n:Number = randRange(1, 13) 
    trace(n); 
}

if (n == 1) {
	gotoAndPlay (50); 
} else if (n == 2) {
	gotoAndPlay (50); 
} else if (n == 3) {
	gotoAndPlay (85);
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I am trying something different.  I have a number generate and it tells me the number in the output tab, however how do I call the number to my if else statement.  I have a bit of the code here:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> randRange<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">min</span>:<span style="color: #0066CC;">Number</span>, <span style="color: #0066CC;">max</span>:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> randomNum:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">floor</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">max</span> - <span style="color: #0066CC;">min</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #0066CC;">min</span>; 
    <span style="color: #b1b100;">return</span> randomNum; 
<span style="color: #66cc66;">&#125;</span> 
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i = <span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">1</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> n:<span style="color: #0066CC;">Number</span> = randRange<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> 
    <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span>; 
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>n == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">gotoAndPlay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>n == <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">gotoAndPlay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>n == <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">gotoAndPlay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Shebby</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6756</link>
		<dc:creator>Shebby</dc:creator>
		<pubDate>Tue, 19 Oct 2010 15:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6756</guid>
		<description>The post was a tutorial about using Math.random(), not how to build an asteroid game from start to finish.</description>
		<content:encoded><![CDATA[<p>The post was a tutorial about using Math.random(), not how to build an asteroid game from start to finish.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Henson Creighton</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6747</link>
		<dc:creator>Ryan Henson Creighton</dc:creator>
		<pubDate>Fri, 15 Oct 2010 23:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6747</guid>
		<description>Thanks, Janik!</description>
		<content:encoded><![CDATA[<p>Thanks, Janik!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Janik</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6743</link>
		<dc:creator>Janik</dc:creator>
		<pubDate>Thu, 14 Oct 2010 08:53:15 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6743</guid>
		<description>Thanks a lot for this simple yet helpflul tutorial.
Cheers</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this simple yet helpflul tutorial.<br />
Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Freddy</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6711</link>
		<dc:creator>Freddy</dc:creator>
		<pubDate>Fri, 08 Oct 2010 16:25:03 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6711</guid>
		<description>totalAsteroids is undefined, screenRange is undefined, speedRange is undefined. Your tutorial using Math.random was great but why are you illustrating with an example that is uncompleted ?
I am going to start wondering if you really know how to build real programs Sir.:)</description>
		<content:encoded><![CDATA[<p>totalAsteroids is undefined, screenRange is undefined, speedRange is undefined. Your tutorial using Math.random was great but why are you illustrating with an example that is uncompleted ?<br />
I am going to start wondering if you really know how to build real programs Sir.:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bergen</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6476</link>
		<dc:creator>Bergen</dc:creator>
		<pubDate>Wed, 15 Sep 2010 20:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6476</guid>
		<description>Good work!  And good point about Math.round for 0-0.499 being less likely than .5-1.499, Dennis. However, there is one thing all of you are missing.

From the ActionScript Reference on Math:
  random():Number
  [static] Returns a pseudo-random number n, where 0 &lt;= n &lt; 1.

So, we can return 0, but never 1

You had said:
var someNum:Number = Math.ceil(Math.random()*5);
// gives you 1, 2, 3, 4, or 5 by raising the decimal number

BUT, Math.ceil(Math.random()*5) will, a very very small percentage of the time, return 0… and THAT my friends, is where babies come from.  I mean bugs.</description>
		<content:encoded><![CDATA[<p>Good work!  And good point about Math.round for 0-0.499 being less likely than .5-1.499, Dennis. However, there is one thing all of you are missing.</p>
<p>From the ActionScript Reference on Math:<br />
  random():Number<br />
  [static] Returns a pseudo-random number n, where 0 &lt;= n &lt; 1.</p>
<p>So, we can return 0, but never 1</p>
<p>You had said:<br />
var someNum:Number = Math.ceil(Math.random()*5);<br />
// gives you 1, 2, 3, 4, or 5 by raising the decimal number</p>
<p>BUT, Math.ceil(Math.random()*5) will, a very very small percentage of the time, return 0… and THAT my friends, is where babies come from.  I mean bugs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6103</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Sat, 24 Jul 2010 22:30:28 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6103</guid>
		<description>Cody - thanks for the additional code!  It really surprises me that this post remains the most popular one on the site for a number of years.</description>
		<content:encoded><![CDATA[<p>Cody &#8211; thanks for the additional code!  It really surprises me that this post remains the most popular one on the site for a number of years.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cody</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-6088</link>
		<dc:creator>Cody</dc:creator>
		<pubDate>Tue, 20 Jul 2010 07:30:50 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-6088</guid>
		<description>Ryan,

Thanks a bunch for the tut, working knowledge of random numbers is definitely something a budding programmer needs to know.

In reference to as3 beginner&#039;s post, he or she is correct to say that:

var minLimit:Number = 5;
var maxLimit:Number = 20;
var range:Number = maxLimit - minLimit;
var someNum:Number = Math.ceil(Math.random() * range) + minLimit;

...would return 6-20, not 5-20. Reason being the lowest possible return value of &quot;Math.ceil(Math.random() * range)&quot; is 1, and 1+ 5 = 6. 
Changing the minimum to 4, however, will yield 5-19, leaving us one short of the maximum of 20. If the range is increased to 16, we finally get our target return of 5-20. So, to get the true minimum and maximum of the variables we have declared, we modify our code to look like this:

var minLimit:Number = 5;
var maxLimit:Number = 20;
var range:Number = maxLimit - minLimit + 1;
var someNum:Number = Math.ceil(Math.random() * range) + minLimit - 1;
trace(someNum);

Copy/pasting this code and running it in Flash will reveal that the numbers you get are, indeed, from 5 to 20. Hope this helps. Though, it wouldn&#039;t help nearly as much as this tutorial. I&#039;m very grateful for the writeup -- keep up the good work.

--Cody</description>
		<content:encoded><![CDATA[<p>Ryan,</p>
<p>Thanks a bunch for the tut, working knowledge of random numbers is definitely something a budding programmer needs to know.</p>
<p>In reference to as3 beginner&#8217;s post, he or she is correct to say that:</p>
<p>var minLimit:Number = 5;<br />
var maxLimit:Number = 20;<br />
var range:Number = maxLimit &#8211; minLimit;<br />
var someNum:Number = Math.ceil(Math.random() * range) + minLimit;</p>
<p>&#8230;would return 6-20, not 5-20. Reason being the lowest possible return value of &#8220;Math.ceil(Math.random() * range)&#8221; is 1, and 1+ 5 = 6.<br />
Changing the minimum to 4, however, will yield 5-19, leaving us one short of the maximum of 20. If the range is increased to 16, we finally get our target return of 5-20. So, to get the true minimum and maximum of the variables we have declared, we modify our code to look like this:</p>
<p>var minLimit:Number = 5;<br />
var maxLimit:Number = 20;<br />
var range:Number = maxLimit &#8211; minLimit + 1;<br />
var someNum:Number = Math.ceil(Math.random() * range) + minLimit &#8211; 1;<br />
trace(someNum);</p>
<p>Copy/pasting this code and running it in Flash will reveal that the numbers you get are, indeed, from 5 to 20. Hope this helps. Though, it wouldn&#8217;t help nearly as much as this tutorial. I&#8217;m very grateful for the writeup &#8212; keep up the good work.</p>
<p>&#8211;Cody</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5899</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 01 Jun 2010 23:55:30 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5899</guid>
		<description>conscience - i could be wrong, but i remember hearing or reading somewhere that substring operations are slow.  What you&#039;ve done here takes less typing than the array method, but it may not execute as quickly.  If you&#039;re not too concerned about speed, then i say &quot;go with whatever works.&quot;</description>
		<content:encoded><![CDATA[<p>conscience &#8211; i could be wrong, but i remember hearing or reading somewhere that substring operations are slow.  What you&#8217;ve done here takes less typing than the array method, but it may not execute as quickly.  If you&#8217;re not too concerned about speed, then i say &#8220;go with whatever works.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: conscience</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5894</link>
		<dc:creator>conscience</dc:creator>
		<pubDate>Tue, 01 Jun 2010 18:14:22 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5894</guid>
		<description>Thanks.

I made It with String.


var a : String = &quot;qweertyiop[asdjhfmvxcjhgf&quot;;

and take random letter from It. maybe it is faster?</description>
		<content:encoded><![CDATA[<p>Thanks.</p>
<p>I made It with String.</p>
<p>var a : String = &#8220;qweertyiop[asdjhfmvxcjhgf&#8221;;</p>
<p>and take random letter from It. maybe it is faster?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5889</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 01 Jun 2010 15:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5889</guid>
		<description>conscience: You can either build your own discreet array, and choose a random index in that array:

aLetters = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;];

or you could pull a random number using the keycodes or ascii codes for the letters.  Use this table for reference:

http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00001136.html

- Ryan</description>
		<content:encoded><![CDATA[<p>conscience: You can either build your own discreet array, and choose a random index in that array:</p>
<p>aLetters = ["A", "B", "C"];</p>
<p>or you could pull a random number using the keycodes or ascii codes for the letters.  Use this table for reference:</p>
<p><a href="http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00001136.html" rel="nofollow">http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00001136.html</a></p>
<p>- Ryan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: conscience</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5886</link>
		<dc:creator>conscience</dc:creator>
		<pubDate>Mon, 31 May 2010 14:16:40 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5886</guid>
		<description>Hi!
How to get random letter? for example, you can get random color.


Math.random()*0xffffff</description>
		<content:encoded><![CDATA[<p>Hi!<br />
How to get random letter? for example, you can get random color.</p>
<p>Math.random()*0xffffff</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randomly placing a child on the stage &#124; kitstop.co.nz</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5707</link>
		<dc:creator>Randomly placing a child on the stage &#124; kitstop.co.nz</dc:creator>
		<pubDate>Mon, 03 May 2010 09:46:10 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5707</guid>
		<description>[...] it was going  little too well. This required some research and the best tutorial I could find is here at the awesome site untoldentertainment.com. Make sure you read the comments as they discuss the [...]</description>
		<content:encoded><![CDATA[<p>[...] it was going  little too well. This required some research and the best tutorial I could find is here at the awesome site untoldentertainment.com. Make sure you read the comments as they discuss the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5414</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 22 Mar 2010 17:47:01 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5414</guid>
		<description>Matt - thanks!  Would you believe that this article remains the most high-traffic page on my site?</description>
		<content:encoded><![CDATA[<p>Matt &#8211; thanks!  Would you believe that this article remains the most high-traffic page on my site?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-5411</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Mon, 22 Mar 2010 08:19:28 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-5411</guid>
		<description>Thanks for this.
Fast and made sense.</description>
		<content:encoded><![CDATA[<p>Thanks for this.<br />
Fast and made sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pooja</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-4634</link>
		<dc:creator>Pooja</dc:creator>
		<pubDate>Sun, 15 Nov 2009 11:42:10 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-4634</guid>
		<description>good tutorial.....Thanks</description>
		<content:encoded><![CDATA[<p>good tutorial&#8230;..Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: as3 beginner</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3897</link>
		<dc:creator>as3 beginner</dc:creator>
		<pubDate>Fri, 04 Sep 2009 22:59:19 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3897</guid>
		<description>LOL my mistake   I ment when you add  5 to a set of 1 to 15**  you get 6 to 20** &gt;&lt;

is that right?      adding 0 gives u 1 to 15... adding 4 would get you  5 to 19  , adding 5 gives you 6** to 20..

Goes back to study more flash coding :)   Peace...</description>
		<content:encoded><![CDATA[<p>LOL my mistake   I ment when you add  5 to a set of 1 to 15**  you get 6 to 20** &gt;&lt;</p>
<p>is that right?      adding 0 gives u 1 to 15&#8230; adding 4 would get you  5 to 19  , adding 5 gives you 6** to 20..</p>
<p>Goes back to study more flash coding :)   Peace&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: as3 beginner</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3868</link>
		<dc:creator>as3 beginner</dc:creator>
		<pubDate>Thu, 03 Sep 2009 17:24:19 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3868</guid>
		<description>Thank you this was just what i was searching for,  Thanks to you and google , I found it :)

one other note:   if you add 5 to the range or 1-20   you get 6 to 21

var someNum:Number = Math.ceil(Math.random()*15);
// gives you 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, or 15
var someNum:Number = Math.ceil(Math.random()*15) + 5;
// gives you 5, 6, 7, 8, ,9 ,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, or 20

add 4 instead :)

Loves Math ^_^</description>
		<content:encoded><![CDATA[<p>Thank you this was just what i was searching for,  Thanks to you and google , I found it :)</p>
<p>one other note:   if you add 5 to the range or 1-20   you get 6 to 21</p>
<p>var someNum:Number = Math.ceil(Math.random()*15);<br />
// gives you 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, or 15<br />
var someNum:Number = Math.ceil(Math.random()*15) + 5;<br />
// gives you 5, 6, 7, 8, ,9 ,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, or 20</p>
<p>add 4 instead :)</p>
<p>Loves Math ^_^</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3669</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Wed, 19 Aug 2009 17:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3669</guid>
		<description>Good job man. Helped e more than most tuts! Keep it up. God bless</description>
		<content:encoded><![CDATA[<p>Good job man. Helped e more than most tuts! Keep it up. God bless</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3650</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Wed, 19 Aug 2009 00:21:11 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3650</guid>
		<description>Ryan - thanks for your request!  i&#039;ll get right on it.

- Also Ryan</description>
		<content:encoded><![CDATA[<p>Ryan &#8211; thanks for your request!  i&#8217;ll get right on it.</p>
<p>- Also Ryan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3649</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 18 Aug 2009 22:50:13 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3649</guid>
		<description>Love the Tutorial! You said if we had any request just ask, well......... Sorry if this seems a little simple but have been looking for a basic tutorial for age on this to get a firm understanding. Classes for beginners! making and using basics. I see you have related tuts to this but would love some more info.</description>
		<content:encoded><![CDATA[<p>Love the Tutorial! You said if we had any request just ask, well&#8230;&#8230;&#8230; Sorry if this seems a little simple but have been looking for a basic tutorial for age on this to get a firm understanding. Classes for beginners! making and using basics. I see you have related tuts to this but would love some more info.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3382</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Mon, 06 Jul 2009 21:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3382</guid>
		<description>Thanks, Dennis.  Math and i haven&#039;t really spoken to each other since high school. Our relationship has been a little strained.</description>
		<content:encoded><![CDATA[<p>Thanks, Dennis.  Math and i haven&#8217;t really spoken to each other since high school. Our relationship has been a little strained.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-3381</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Mon, 06 Jul 2009 21:16:24 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-3381</guid>
		<description>Hi, nice tutorial there, but I want to say something about your rounding:

random() * 5 gives you a float value between 0 and 5, but when you make it an int by ROUNDing it, you must be aware that 0 and 5 are more unlikely to occure than the other values! because only values from 0..0.49999~ will round to 0 and values 4.5 to 5 will round to 5. 

but e.g. values 0.5..1.4999999~ will all be rounded to 1, so the probability is twice as large.

so one should always go with ceil. 

I&#039;d suggest to write a little helping function to make your code more readable and usable:

function randomInRange(from:int, to:int):int {
  return Math.ceil(Math.random() * (to - from + 1)) + from;
}

// haven&#039;t checked the code, but I hope you just get the picture (so noone should just copy this code without testing ;) - maybe there will be some index-offsets ;) )</description>
		<content:encoded><![CDATA[<p>Hi, nice tutorial there, but I want to say something about your rounding:</p>
<p>random() * 5 gives you a float value between 0 and 5, but when you make it an int by ROUNDing it, you must be aware that 0 and 5 are more unlikely to occure than the other values! because only values from 0..0.49999~ will round to 0 and values 4.5 to 5 will round to 5. </p>
<p>but e.g. values 0.5..1.4999999~ will all be rounded to 1, so the probability is twice as large.</p>
<p>so one should always go with ceil. </p>
<p>I&#8217;d suggest to write a little helping function to make your code more readable and usable:</p>
<p>function randomInRange(from:int, to:int):int {<br />
  return Math.ceil(Math.random() * (to &#8211; from + 1)) + from;<br />
}</p>
<p>// haven&#8217;t checked the code, but I hope you just get the picture (so noone should just copy this code without testing ;) &#8211; maybe there will be some index-offsets ;) )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-2884</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Sun, 15 Mar 2009 14:46:30 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-2884</guid>
		<description>Thanks for the pick-me-up!  You made my day.

i haven&#039;t penned a Flash tutorial in a while.  Part of me worries that i&#039;ll write something that too many people understand, and it&#039;ll have a big &quot;duh&quot; factor to it.  But i can&#039;t discount the fact that different people come in with different levels of experience.

If there&#039;s a tutorial you&#039;d like to see here, or an AS3 issue you&#039;d like cleared up, let me know!</description>
		<content:encoded><![CDATA[<p>Thanks for the pick-me-up!  You made my day.</p>
<p>i haven&#8217;t penned a Flash tutorial in a while.  Part of me worries that i&#8217;ll write something that too many people understand, and it&#8217;ll have a big &#8220;duh&#8221; factor to it.  But i can&#8217;t discount the fact that different people come in with different levels of experience.</p>
<p>If there&#8217;s a tutorial you&#8217;d like to see here, or an AS3 issue you&#8217;d like cleared up, let me know!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/comment-page-1/#comment-2883</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sun, 15 Mar 2009 05:14:21 +0000</pubDate>
		<guid isPermaLink="false">http://untoldentertainment.com/blog/2008/03/23/as3-tutorial-mathrandom/#comment-2883</guid>
		<description>good tutorial. I love your site, couldn&#039;t bookmark it quick enough. The animation in your navigation and all the hand drawn elements are amazing.</description>
		<content:encoded><![CDATA[<p>good tutorial. I love your site, couldn&#8217;t bookmark it quick enough. The animation in your navigation and all the hand drawn elements are amazing.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

