Re: [問題] 亂數取值不包含特定的數

看板Flash作者 (CJ Cat)時間13年前 (2012/03/26 04:34), 編輯推噓3(304)
留言7則, 4人參與, 最新討論串3/3 (看更多)
※ 引述《kencool107 (臉都歪了)》之銘言: : 如果我想要取亂數0~4 : Math.round(Math.random()*4)是這樣寫 : 但是如果我想取亂數0~4但不包含3 : 那我要怎麼寫呀? : 教教我 var range:Vector.<int> = Vector.<int>([0, 1, 2, 4]); var randomNumber:int = range[int(Math.random() * 4)]; -- Blog http://blog.cjcat.net Gallery http://cjcat2266.deviantart.com ptt2 Board CJWorkshop -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 72.5.59.140 ※ 編輯: cjcat2266 來自: 72.5.59.140 (03/26 04:35)

03/26 15:17, , 1F
我想到的也是這招,把不想被發的牌直接抽掉 :)
03/26 15:17, 1F

03/26 15:18, , 2F
var num:Array = [0, 1, 2, 4]
03/26 15:18, 2F

03/26 15:18, , 3F
trace(num[int(Math.random()*num.length)])
03/26 15:18, 3F

03/26 15:19, , 4F
可惜AS3沒內建的shuffle,不然可以再更短一點
03/26 15:19, 4F

03/28 00:20, , 5F
讚~~~
03/28 00:20, 5F

03/30 18:03, , 6F
受教了 謝謝
03/30 18:03, 6F

03/30 18:08, , 7F
平時在下也是用一樓的array法
03/30 18:08, 7F
文章代碼(AID): #1FRu5aLE (Flash)
文章代碼(AID): #1FRu5aLE (Flash)