News:

Holy shit, it's 2018 2019 2020 2021 2022 2023 2024, and the US isn't a fascist country! What a time to be alive. Well, shit.

Main Menu

Help?

Started by AntiVirus, October 14, 2006, 04:27:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sidoh

Quote from: AntiVirus on October 14, 2006, 10:20:10 PM
So then shouldn't it be:

x = (rang()%20) + 5?

No!  If you devide something by 20, you can never have remander 20!  Think about what modulus means.

iago

Quote from: AntiVirus on October 14, 2006, 10:20:10 PM
So then shouldn't it be:

x = (rang()%20) + 5?

rang()? :P

Sorry, I think I missed a -1 in my formula.  Sorry :P

rand() % 20 returns a random number between 0 and 19, inclusive
+5 makes it 5 to 24.  The range is actually off by one.

Sidoh

Quote from: iago on October 15, 2006, 12:25:07 AM
Quote from: AntiVirus on October 14, 2006, 10:20:10 PM
So then shouldn't it be:

x = (rang()%20) + 5?

rang()? :P

Sorry, I think I missed a -1 in my formula.  Sorry :P

rand() % 20 returns a random number between 0 and 19, inclusive
+5 makes it 5 to 24.  The range is actually off by one.

You mean a + 1?  I see why saying -1 is valid too, but it's terribly misleading!