Quote:
Originally Posted by cbk1994
Those are some of the most weirdly complicated ways of doing this I've seen.
PHP Code:
function pickRandomNumber() {
if (random(0, 1) < 0.5) {
return 5;
} else {
return 10;
}
}
Usually the simplest solution is best. Code readability > tricky math. It's a lot easier to look at mine and see what it does than it is to stop and mentally parse out int(random(1,2.9))*5.
|
Bah, this is elementry level math. Nothing tricky about it.. Had it been more complicated, yes I would have done like chris showed however I prefer doing it as BlueMelon showed at that point. It was just kinda the first thing that poped into my head to help, without adding a bunch of lines to his script.