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
|
shell代码 1 :
#!/bin/bash a = ($(($RANDOM % 10 + 1 )))
e = 0
while :
do b = $(($RANDOM % 10 + 1 ))
c = 0
for i in ${a[ * ]}
do
if [ $i - eq $b ];then
c = 1
fi
done
if [ $c - eq 0 ];then
a[$e] = $b
let e + +
fi
d = ${ #a[*]}
if [ $d - eq 10 ];then
break
fi
done echo ${a[ * ]}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ shell代码 2 :
#!/bin/bash a = ( 1 2 3 4 5 6 7 8 9 10 )
while :
do b = $(($RANDOM % 10 ))
if [ "${a[$b]}" ! = "" ];then
echo ${a[$b]}
unset a[$b]
fi
[ ${ #a[*]} -eq 0 ] && break
done #!/bin/bash a = ( 1 2 3 4 5 6 7 8 9 10 )
while :
do b = $(($RANDOM % 10 ))
[ "${a[$b]}" ! = "" ] && echo ${a[$b]} && unset a[$b]
[ ${ #a[*]} -eq 0 ] && break
done #!/bin/bash for i in { 1. . 10 };do
echo "$RANDOM $i" >> / tmp / ran.txt
done sort - n / tmp / ran.txt|awk '{print $2}'
rm - rf / tmp / ran.txt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ python代码: #!/usr/bin/env python import random
l = range ( 1 , 11 )
random.shuffle(l) print l
|
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任
本文转自 CrazyWing 51CTO博客,原文链接:http://blog.51cto.com/fklinux/1980541