how to test when correct output is "random"?

Greg Ewing (using ckea25d02 at
Mon Apr 7 04:57:40 CEST 2003

Steven Taschuk wrote:
> Consider two implementations of this function:
> 	def permute(seq):
> 		"""Returns a copy of seq, randomly permuted."""
> 		# ...

In that kind of situation, what you should probably
be checking is not that a particular permutation is
produced, but just that the output is *some* permutation
of the input.

You may also want to call it a few times and check
that it returns a different permutation each time.

That's probably good enough to pick up whether you've
broken anything.

If you're worried that the output might pass those
tests but still not be random enough, then you're
into statistical testing, as Mr. Tasch suggested.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list