Quote Rotator Logic Error

xbolt

Medic
Joined
Apr 23, 2008
Messages
7
Reaction score
3
The quote rotation script at the top of the page has a logic error, making it so the first and last entries in the array come up less often than the rest.

This part right here:
var whichQuotation=Math.round(Math.random()*(Q-1));

It uses Math.round, which just rounds to the nearest integer. This works, but the first entry in the array only comes up if the generated number is between 0 and 0.5. That's a range of only 0.5. The second entry in the array comes up if the generated number is between 0.5 and 1.5, a range of 1. Now, the last entry only comes up if the number generated is between 2.5 and 3, making the range 0.5 again.

Here is corrected code:
var whichQuotation=Math.floor(Math.random()*(Q));

It looks similar, but uses Math.floor instead, so it only rounds down. So everything between 0 and 1 becomes 0, everything between 1 and 2 becomes 1, and so on. This makes it so all the entries have the same chance of showing up.
 
Oh, wow.

I'd say your my favorite new member but you've been around a while, despite having very few posts.

I just like this thread.
 
I've just implemented this, but can't tell it's made much of a difference.

But thank you.
 
Wow, that was fast.

Thanks. Yeah, I got an account years ago, and am on a lot, but never post much.

It's not TOO much of a difference. Just something that, me being a web designer, bugged me. ;)
 
Vegeta used the post rating system? :O

Bro I've used it like way more than you.

VTLmo.png
 
I didn't even know you can check people are using it, nor do I care. Just kind of funny considering your crusade in the Facebook page during the transition.
 
Wow, that was fast.

Thanks. Yeah, I got an account years ago, and am on a lot, but never post much.

It's not TOO much of a difference. Just something that, me being a web designer, bugged me. ;)
We are phenomenally quick at everything. Ask our wives.
 
Hmm. The site's still showing the old code...
 
Weird. It had definitely changed the other day.

Changed it again.
 
Back
Top