// random_generator.cpp
//
// Priklad na pretizeny operator volani funkce ()
//
// Generator pseudonahodnych cisel v rozmezi 0 .. limit-1
// Pretizeny operator () vraci pseudonahodne cislo
//
// Chceme-li pouzit jiny generator, muzeme od teto tridy odvodit potomka
// Metoda operator() je virtualni, takze k problemum nedojde
#ifdef _WIN32
	#include <tchar.h>
	#include <conio.h>
#elif (defined __linux__) || (defined _AIX) || (defined __APPLE__)
	typedef char _TCHAR;
	#define _tmain main
#endif

#include <limits.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;

class generator {
	int limit;
public:
	void NastavMez(long mez) { limit = mez; }
	generator(int mez = INT_MAX) :limit(mez) {}
	virtual int operator()();
};

int generator::operator()(void) {
	return rand() % limit; // Pouzijeme standardni generator
}

generator G6(6);		// Instance: generator nahodnych celych cisel v rozmezi 0..5
generator G100(100); // Instance: generator nahodnych celych cisel v rozmezi 0..99

void my_getch();

int main()
{
	cout << endl;
	srand((unsigned)time(NULL)); // NEZABUDNUT INICIALIZOVAT GENERATOR  !!!!!!!!!!!!
	for (int i = 0; i < 10; i++)
		cout << G6() << endl; // Nejake pouziti
	cout << endl;
	for (int i = 0; i < 10; i++)
		cout << G100() << endl; // Nejake pouziti
	my_getch();
	return 0;
}
//---------------------------------------------------------------------------
void my_getch()
{
#ifdef _WIN32
	_getch();
#else
	cout << endl;
#endif
}
//---------------------------------------------------------------------------
