Link to home
Start Free TrialLog in
Avatar of ceena
ceena

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of ecebhume
ecebhume

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of terajiv
terajiv

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
Follow ecebhume's advice, wrap it in a small function:
  inline int
  random(int n)
 {
    return rand() % n;
 }
Avatar of ceena

ASKER

Thanks all.