Programming is about elegance. Yesterday someone asked me how to write a program that displays six unique random numbers (1 to 9). The beauty of this problem is that it is exceedingly simple to solve, but still leaves room for some awesome-source.

Here’s the simple solution in PHP (I make no claims to this being awesome):

$used = array();
for($i=0; $i<6; $i++){
	$x=rand(1,10);

	while(in_array($x,$used)){
		$x=rand(1,10);
	}

	$used[] = $x;
	echo $x . ' ';
}

Notice that this isn't a battle for who can do this in the least lines.

I duly expect to be beaten on the head for some or other bad PHP habit. I'm also expecting people to submit the solution in Perl, Python, Erlang, Ruby, C, C++, Java and anything else you feel like trying your hand at.

ps. Wrap your solutions in <pre> tags.