should add some code here to error check that the number of bytes generated is equal to n