作者aquarianboy (一路好走..)
看板Flash
标题Re: [问题] 想请问flash高手...这程式哪里出问题?
时间Sun Nov 19 12:53:16 2006
※ 引述《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