CMPC
Would you like to react to this message? Create an account in a few clicks or log in to continue.

The Randnum Function

2 posters

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

Go down

The Randnum Function Empty The Randnum Function

Post by Admin 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
Admin
Admin
Pirate King

Posts : 559

Back to top Go down

The Randnum Function Empty Re: The Randnum Function

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

I personally use (rnd * (max - min)) + min
Corey
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