#!/bin/bash # declare -a ARRAY read -p "Please input num[1-39]:" EMENUM #对比新生成的随机数是否重复 function COMELE { for J in `seq 1 ${#ARRAY[@]}`;do if [ $1 -eq ${ARRAY[$J]} ]; then return 1 fi done return 0 } for I in `seq 1 $EMENUM`; do while true; do ELEMENT=$[$RANDOM%40] COMELE $ELEMENT if [ $? -eq 0 ]; then break fi done ARRAY[$I]=$ELEMENT echo "${ARRAY[$I]}" done
时间: 2024-12-20 08:41:01