[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

generating random numbers between a desired interval

Posted on 2005-05-02
1
Medium Priority
?
418 Views
Last Modified: 2012-05-05
Hello experts.
I would like to know how I can generate random numbers in the interval between 1 and 100. I don't want 0 to be included.
I tried using rand() with time(0) and then doing the %100. But with this process the 0 is included.
Any way so that the 0 is not included?
Thanks.
0
Comment
Question by:gjgomez
1 Comment
 
LVL 16

Accepted Solution

by:
nonubik earned 2000 total points
ID: 13915649
If you want a random number between 1 and 100 (including 1 and 100) try using rand() with time(0) and then %100 (gets a random between 0 and 99) and then + 1 (gets a random between 1 and 100).
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question