Some edits to ensure randomness where randomness is expected.