Re: [問題] 想請問flash高手...這程式哪裡出問題?
※ 引述《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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 8 篇):
Flash 近期熱門文章
PTT數位生活區 即時熱門文章