Quote:
Originally Posted by Old Pedant
Of you could do it thus:
Code:
var rarityNum = Math.floor( 1 + Math.random() * 100 );
var rarity = ( rarityNum > 95 ) ? "rare"
: ( rarityNum > 65 ) "uncommon"
: "common";
Naturally you can control the numbers (here 95 and 65) as you want.
rarityNum, as I coded it, will be a number form 1 to 100.
So also as coded, there is a 5% chance you will get "rare", 30% chance for "uncommon", and 65% chance for "common".
|
I think you missed one little '?' in your last example.
Code:
<script type="text/javascript">
var rarityNum = Math.floor( 1 + Math.random() * 100 );
var rarity = ( rarityNum > 95 ) ? "rare"
: ( rarityNum > 65 ) ? "uncommon"
: "common";
alert(rarity)
</script>
Looks like it's not only my lighting fast phalanges that can get away from me.