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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Changing the value of RAND_MAX is a very bad idea.
Go with ecubhume's solution
Luc
Go with ecubhume's solution
Luc
Follow ecebhume's advice, wrap it in a small function:
inline int
random(int n)
{
return rand() % n;
}
inline int
random(int n)
{
return rand() % n;
}
ASKER
Thanks all.
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