The Randnum Function

CMPC :: Computing :: Programming :: C++

Go down

The Randnum Function

Post by Admin on Thu Dec 31, 2009 2:46 am

I just added this to my DevC++ library yesterday seeing as how often i use it.

here you go.


Code:
#ifndef _RANDNUM_H_
#define _RANDNUM_H_

#include <ctime>
#include <cstdlib>

using namespace std;

int randnum(int lownum, int highnum)
{
srand((unsigned)time(0));
   
   return (rand()%(highnum+1)+lownum);

}

#endif
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: The Randnum Function

Post by Corey on Thu Dec 31, 2009 3:50 am

I personally use (rnd * (max - min)) + min

_________________
-Corey Hoard

(Yes, I totally copied Paul's avatar. Or, at least attempted to.)
avatar
Corey
Mod

Posts : 462

Back to top Go down

Back to top


CMPC :: Computing :: Programming :: C++

 
Permissions in this forum:
You cannot reply to topics in this forum