Random synthesis with saving and memoization