Restructure and add simple rand algorithm