1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #!/bin/bash
let LENGTH=$1
MAX=$1
COMBINAISONS=1
LETTRES=$2
while [ $LENGTH != 1 ]
do
COMBINAISONS=`expr $COMBINAISONS \* $LENGTH`
let LENGTH-=1
done
echo "Combinaisons: $COMBINAISONS"
echo "Nombre de parametres=$#"
LETTRES=""
while [ $# != 1 ]
do
shift
if [ "$LETTRES" == "" ] ; then
LETTRES="$1"
else
LETTRES="${LETTRES}_$1"
fi
done
echo "Lettres = [$LETTRES]"
found=0
TOUS_LES_MOTS=""
while [ $found != $COMBINAISONS ] ; do
let n=0
MOT=""
INDEX_STRING=""
while [ $n != $MAX ] ; do
let index_trouve=1
while [ $index_trouve == 1 ] ; do
index=`expr $RANDOM % $MAX`
let trouve=0
for un_index in $INDEX_STRING
do
if [ "$un_index" == "$index" ] ; then
let trouve=1
fi
done
if [ $trouve != 1 ] ; then
let index_trouve=0
INDEX_STRING="$INDEX_STRING $index "
fi
done
let index+=1
L=`echo $LETTRES | cut -d _ -f $index`
MOT="${MOT}$L"
let n+=1
done
let trouve=0
for un_mot in $TOUS_LES_MOTS
do
if [ "$un_mot" == "$MOT" ] ; then
let trouve=1
fi
done
if [ $trouve == 0 ] ; then
TOUS_LES_MOTS="${TOUS_LES_MOTS} $MOT"
let found+=1
echo "Mot genere ==> [$MOT]"
fi
done
echo "TOUS les mots: [$TOUS_LES_MOTS]" |
Partager