basic generator algorithm