By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,137 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,137 IT Pros & Developers. It's quick & easy.

what this function do

100+
P: 254
i have this:
Expand|Select|Wrap|Line Numbers
  1. inline unsigned GetRandom(unsigned min, unsigned max) {
  2.        return rand() % (max - min + 1) + min;
  3. }
  4.  
i dont know what it means and does it return one value only?
Dec 30 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
i have this:
Expand|Select|Wrap|Line Numbers
  1. inline unsigned GetRandom(unsigned min, unsigned max) {
  2.        return rand() % (max - min + 1) + min;
  3. }
  4.  
i dont know what it means and does it return one value only?
this gives a pseudo random number between min and max, i.e. % has a higher precedence than + so the expression is
Expand|Select|Wrap|Line Numbers
  1.    (rand() % (max - min + 1)) + min
  2.  
the subexpression rand() % (max - min + 1) gives a number between 0 and max-min and then min is added to the result
Dec 30 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.