Code:
class UniqueRand
{
private:
int min, max, OptionsLeft;
bool bUsed[];
public:
void Initialize(int min=0, int max=1000)
{
this.min = min;
this.max = max;
bUsed = new bool[max-min];
}
int Random()
{
for(int i=0; i<max-min; i++)
{
if(bUsed[i]==false)
{
OptionsLeft++;
}
}
if(OptionsLeft==0)
{
return -1;
}
int retval = (rand()%(max-min));
while(bUsed[retval]==true)
{
retval = (rand()%(max-min));
}
bUsed[retval]=true;
OptionsLeft=0;
return (retval+min);
}
void Reset()
{
for(int i=0; i<max-min; i++)
{
bUsed[i]=false;
}
}
};
usage:
Code:
UniqueRand myRandGen;
myRandGen.Initialize(20,500);
int mygeneratedrang = myRandGen.Random();
note: written in here, so untested meaning it will probably throw some errors at you =P