today's offers - xanax use in pregnancy xanax xr be abused soma internet pharmacies fedex soma without priscription fed ex phentermine parkinson drugs phentermine baclofen tramadol together ordering tramadol cod viagra find search 76k cialis pages cialis buy on line viagra for sale without a prescription buy onlinecom phentermine viagra ambien and klonopin drug interaction buy ambien overnight cheap online pharmacies valium saturday delivery valium online with no prescription or membership fioricet overnight no rx cheap fioricet without a prescription order meridia cod fedex meridia cheap fed ex delivery xanax bradycardia what does xanax look like american soma how to buy soma online without prescriptin phentermine overnight echeck c o d 375 mg phentermine rss feed cheap no prescription tramadol stop the tramadol generic prices online cialis generic cialis fedex chinese herbal viagra taking partial pill of viagra ambien and pregnancy smoking ambien cod online valium buy cheap valium without prescription no prescription fioricet with fedex fioricet without prescription in Brasilia order meridia meridia information

程式的功力差別!!!!


今天在寫apollo的ad 部份
有一個部份是在實做百面骰的部份
用百面骰的概念來實做百分比的呈現
例如我有5個值
a 的 比例是20,
b 的 比例是30,
c 的 比例是50,
d 的 比例是80,
f 的 比例是160
然後依比例來讓他們呈現應有的次數
最直接想的是
直接塞個20+30+50+80+160 的array
不過覺得這樣做實在是挺白痴的
覺得應該有更好的方法
經過”貓哥”的小小提示”區間”
我想到的是
$rand = rand(1,$ad_total);
用for 來做
if (0 <= $rand<= a){
return a;
} elseif ( a < $rand <=b ){
return b;
}
一直下去。
不過貓哥寫的是這樣
$rand = rand(1,$ad_total);
for ($i=0; $i $rand = $rand – $rand_row[$i]['percentage'];
if ($rand < 0) {
break;
}
}
一看就覺得我自已像笨蛋一樣…………………..
有很深的体會,程式寫的好的和不好的差別,真的是一眼就看出來了。 ::S:

  1. No comments yet.
(will not be published)

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word