added algorithm for error generation