Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

RodrigoGroff

Randomic func for RPG battle system

This topic is 6775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi you all. This WAS my func : int iGetRandom(int iMax,int iDif) { int temp=0; if (!iMax) return 0; srand(rand()); while ((temp < iMax - iDif) // (temp > iMax)) temp = rand(); return temp; } this is WRONG, dont try it! (yes it works ,but bad) Thanks to Kylotan i got the perfect line : temp = (int)((double)rand() / ((double)RAND_MAX + 1) * iDif) + (iMax - iDif); Does Anyone have a new idea ?

Share this post


Link to post
Share on other sites
Advertisement

srand(rand());

Hmm, i think that part is kinda bad. you should do a
srand((unsigned int) (time(&t)));
somewhere (not in the func, and only once)

where t is a time_t




========================
Game projects:
www.fiend.cjb.net

Share this post


Link to post
Share on other sites
the most usual random function i see/use is

int Random(int min, int max)
{
return((rand()%(max-min+1)+min);
}

you could also do the thing with converting to double and using RAND_MAX

of course, it is usually preceded by srand(timeGetTime());

Share this post


Link to post
Share on other sites
Jonatan, it''s better to pass NULL to time() rather than a time_t since you''re only going to use time()''s return value (srand(time(NULL)). This is better because you don''t have to waste valuable memory on a time_t

/. Muzzafarath

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!