We help IT Professionals succeed at work.

How can i generate a random no within 100????

ceena
ceena asked
on
188 Views
Last Modified: 2010-05-18
Hi !

                           I used rand()  fn to generate a random no.How can i define the max limit for that....there
                   is  RAND_MAX....but i want to override that....

                   Can anyone pls help.....

                   Thanks in advance.
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
If u want to increase the range of Random Numbers then u can use srand() function from Stdlib.h
or If u want to give ur own value then try opening stdlib.h and modify the value of RAND_MAX in it. Im not Very Sure of second thing Just Check it.
All the Best
Changing the value of RAND_MAX is a very bad idea.
Go with ecubhume's solution
Luc

Commented:
Follow ecebhume's advice, wrap it in a small function:
  inline int
  random(int n)
 {
    return rand() % n;
 }

Author

Commented:
Thanks all.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.