
{"id":720,"date":"2009-01-21T09:00:07","date_gmt":"2009-01-21T08:00:07","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/?p=720"},"modified":"2009-01-13T23:21:37","modified_gmt":"2009-01-13T22:21:37","slug":"from-as2-to-as3-where-did-it-go-random","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2009\/01\/21\/from-as2-to-as3-where-did-it-go-random\/","title":{"rendered":"From AS2 to AS3 &#8211; Where did it go &#8211; random"},"content":{"rendered":"<p>This is one that I figured out pretty quick.<\/p>\n<p>What has the <a href=\"http:\/\/livedocs.adobe.com\/flex\/2\/langref\/migration.html\">ActionScript 2.0 Migration<\/a> to say about this subject:<\/p>\n<table width='95%' border=\"1\" cellpadding=\"0\" cellspacing=\"0\">\n<tr style='background-color:silver'>\n<td><strong>ActionScript&nbsp;2.0&nbsp;<\/strong><\/td>\n<td><strong>ActionScript&nbsp;3.0&nbsp;<\/strong><\/td>\n<td><strong>Comments<\/strong><\/td>\n<\/tr>\n<tr style='background-color:#F5F5F5'>\n<td>random()<\/td>\n<td>Math.random()<\/td>\n<td>Removed. Use Math.random() instead.<\/td>\n<\/tr>\n<\/table>\n<p>I could have seen that coming:<\/p>\n<blockquote><p>Deprecated since Flash Player 5. This function was deprecated in favor of Math.random().<br \/>\nReturns a random integer between 0 and one less than the integer specified in the value parameter.\n<\/p><\/blockquote>\n<p><em>Source: as2 help documentation.<\/em><\/p>\n<p>I was still using it a in Flash 6 and higher, but now I have to change that habit.<\/p>\n<p>And now we come to an annoying point: if you go to the as3 help documentation you only get an explanation but not a nice piece of example code. I don&#8217;t know why they changed that, but I don&#8217;t like it.<\/p>\n<p>So this is the explanation from the as3 help for Math.random()<\/p>\n<blockquote><p>Returns a pseudo-random number n, where 0 <= n < 1. The number returned is calculated in an undisclosed manner, and pseudo-random because the calculation inevitably contains some element of non-randomness. <\/p><\/blockquote>\n<p>with some example code from as2 (functionality isn&#8217;t changed)<\/p>\n<p>[as]<br \/>\n\/\/ The following example outputs 100 random integers between 4 and 11 (inclusively):<br \/>\nfunction randRange(min:Number, max:Number):Number {<br \/>\n    var randomNum:Number = Math.floor(Math.random() * (max &#8211; min + 1)) + min;<br \/>\n    return randomNum;<br \/>\n}<br \/>\nfor (var i = 0; i < 100; i++) {\n    var n:Number = randRange(4, 11)\n    trace(n);\n}\n[\/as]\n\nthe way I using it was somewhat simpler then the example\n\n\n<h3>AS 2<\/h3>\n<p>There are a couple of ways to do that in ActionScript 2:<\/p>\n<p><strong>Example #1<\/strong><br \/>\n[as]random(10)+1; \/\/ to get a number between 1 and 10 (1 and 10 included)[\/as]<\/p>\n<h3>AS 3<\/h3>\n<p>Lets try this in ActionScript 3:<\/p>\n<p><strong>Example #1<\/strong><br \/>\n[as]Math.floor(Math.random()*10)+1; \/\/ to get a number between 1 and 10 (1 and 10 included)[\/as]<\/p>\n<p>Just make a snippet out of it, and you have never to search for this answer&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is one that I figured out pretty quick. What has the ActionScript 2.0 Migration to say about this subject: ActionScript&nbsp;2.0&nbsp; ActionScript&nbsp;3.0&nbsp; Comments random() Math.random() Removed. Use Math.random() instead. I could have seen that coming: Deprecated since Flash Player 5. This function was deprecated in favor of Math.random(). Returns a random integer between 0 and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,172,3],"tags":[68,39,97,229,398,114,168,242],"class_list":["post-720","post","type-post","status-publish","format-standard","hentry","category-as3","category-as3-migration","category-flash","tag-actionscript","tag-as2","tag-as2-to-as3","tag-documentation","tag-flash","tag-from-as2-to-as3","tag-migration","tag-pseudo-random-number"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/comments?post=720"}],"version-history":[{"count":3,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/720\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/720\/revisions\/791"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}