Index: contrib/tools/random_check.sh
===================================================================
--- contrib/tools/random_check.sh	(revision 787510dedb41f02dabf42fdeb6c3236bba791d88)
+++ contrib/tools/random_check.sh	(revision e36a1c2b1bd621aa00e4cca44a8c67a5736b2cf2)
@@ -29,11 +29,31 @@
 #
 
-LOOPS="$1"
-PARALLELISM="$2"
-COMPILERS="$3"
-[ -z "$LOOPS" ] && LOOPS=1
-[ -z "$PARALLELISM" ] && PARALLELISM=1
-# By default, skip icc and native GCC
-[ -z "$COMPILERS" ] && COMPILERS="gcc_cross gcc_helenos clang"
+
+LOOPS=1
+JOBS=1
+MAX_RETRIES=20
+FILENAME_PREFIX=random_run_
+PRUNE_CONFIG_FILE=${FILENAME_PREFIX}prune.config
+
+echo -n "">"$PRUNE_CONFIG_FILE"
+
+while getopts n:j:x: option; do
+	case $option in
+	n)
+		LOOPS="$OPTARG"
+		;;
+	j)
+		JOBS="$OPTARG"
+		;;
+	x)
+		echo "$OPTARG" | tr -d ' ' >>"$PRUNE_CONFIG_FILE"
+		;;
+	*)
+		echo "Usage: $0 [-n loops] [-j paralellism] [-x excluded option [-x ...]]"
+		exit 1
+		;;
+	esac
+done
+
 
 COUNTER=0
@@ -51,6 +71,5 @@
 		# It would be nicer to allow set the constraints directly to
 		# the tools/config.py script but this usually works.
-		# We retry several times if the compiler is wrong and abort if
-		# we do not succeed after many attempts.
+		# We retry $MAX_RETRIES before aborting this run completely.
 		RETRIES=0
 		while true; do
@@ -63,6 +82,17 @@
 			make random-config 2>&1 || exit 1
 			
-			CC=`sed -n 's#^COMPILER = \(.*\)#\1#p' <Makefile.config`
-			if echo " $COMPILERS " | grep -q " $CC "; then
+			tr -d ' ' <Makefile.config >"${FILENAME_PREFIX}config.trimmed"
+			
+			THIS_CONFIG_OKAY=true
+			while read pattern; do
+				if grep -q -e "$pattern" "${FILENAME_PREFIX}config.trimmed"; then
+					THIS_CONFIG_OKAY=false
+					break
+				fi
+			done <"$PRUNE_CONFIG_FILE"
+			
+			rm -f "${FILENAME_PREFIX}config.trimmed"
+			
+			if $THIS_CONFIG_OKAY; then
 				break
 			fi
@@ -97,9 +127,10 @@
 	
 	if [ -e Makefile.config ]; then
-		cp Makefile.config random_run_$COUNTER.Makefile.config
-		cp config.h random_run_$COUNTER.config.h
+		cp Makefile.config "$FILENAME_PREFIX$COUNTER.Makefile.config"
+		cp config.h "$FILENAME_PREFIX$COUNTER.config.h"
 	fi	
 done
 
+rm "$PRUNE_CONFIG_FILE"
 
 echo "Out of $LOOPS tries, $FAILED configurations failed to compile." >&2
