• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

generating random numbers between a desired interval

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?
1 Solution
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).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now