Advertisement

random numbers

Started by October 21, 2000 01:28 AM
2 comments, last by slightlywhacked 24 years, 3 months ago
HEY!!um..... how would I go about getting a random number..between two different numbers..... say I wanted a random number between 5 and 17 how would i code that? int x =rand()% ??????? HELP...plz thank you
BAHcows go moomoos go cow
    int lowNum = 5;int highNum = 17;int numDiff = highNum - lowNum;int r = rand()%numDiff;r = r + lowNum;    


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Advertisement
!! U have to do all that!! well...ok.. thought it wold be like just 1 line of code though

thanx
BAHcows go moomoos go cow
int n = (rand() % (max-min)) + min

there ya go, one line

This topic is closed to new replies.

Advertisement