phpjs
Version:
35 lines (29 loc) • 1.06 kB
HTML
<!-- Generated by Rakefile:build -->
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2012-07-04 15:24:04 <br />
@Kongo: I can see how parseInt is necessary for the min part, but Math.floor should already be creating an integer for the score portion. Still, I do see that PHP seems to cut off the decimal portion for min and max, so I think we should parseInt on both arguments BEFORE calculation to avoid any chance of too high of a max. I have made this change in Git.
<hr />
<strong>
Kongo
</strong>
on 2012-06-29 21:31:56 <br />
Hi ! Your function doesn't work :)
Why ? You don't use parseInt :)
working is :
<pre><code>
function mt_rand (min, max) {
var argc = arguments.length;
if (argc === 0) { min = 0;
max = 2147483647;
} else if (argc === 1) {
throw new Error('Warning: mt_rand() expects exactly 2 parameters, 1 given');
}
var score = Math.floor(Math.random() * (max - min + 1));
score = parseInt(score) + parseInt(min);
return score;
}
</code></pre>
:)
<hr />