Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Random number between limits

Status
Not open for further replies.

RussOSU

Technical User
Apr 16, 2001
93
US
I am needing to create a random number between -3 and +3. I am not sure how to do this using the rand() function. Does anyone have any ideas?

Russ
 
How about generated a random number between zero and six, then subtracting 3?

result = (rand() % 7) - 3;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top