Re: [問題] 想請問flash高手...這程式哪裡出問題?

看板Flash作者 (一路好走..)時間19年前 (2006/11/19 12:45), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/8 (看更多)
※ 引述《jonathanmeow (喵)》之銘言: : function gcd(int1,int2) { : a=Math.max(int1,int2); : b=Math.min(int1,int2); : while(a%b!=0){ : c=a-Math.floor(a/b)*b; : a=b; : b=c; : } : return b; : } : t1=random(31)+1; : t2=random(31)+1; : s1=t1/gcd(t1,t2); : s2=t2/gcd(t1,t2); : trace("7.用新的最簡單整數比求出最大公因數="+gcd(s1,s2)); gcd公式本身看起來並沒什麼問題 我猜,問題是出在random上面 你用的方式:random(31) 這是比較舊式的寫法,查了一下F1的說明: In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. 你可以參考一下F1裡的那段範例: function randRange(min:Number, max:Number):Number { var randomNum:Number; randomNum = Math.floor(Math.random() * (max - min + 1)) + min; return randomNum; } trace(randRange(1, 31)); 供你參考 :) -- http://eddiexx.blogspot.com/ http://www.eddie.com.tw/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.172.127
文章代碼(AID): #15N-5HUn (Flash)
討論串 (同標題文章)
文章代碼(AID): #15N-5HUn (Flash)