Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1285995
  • 博文数量: 168
  • 博客积分: 3483
  • 博客等级: 中校
  • 技术积分: 1696
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-06 13:17
文章分类

全部博文(168)

文章存档

2015年(6)

2014年(9)

2013年(47)

2012年(11)

2011年(13)

2010年(18)

2009年(11)

2008年(42)

2007年(11)

分类: LINUX

2013-12-31 19:24:26


点击(此处)折叠或打开

  1. #! /bin/sh
  2. #
  3. caipiao () {
  4.   awk -v type=$1 '
  5.   function sort(ARRAY, ELEMENTS, temp, i, j) {
  6.         for (i = 2; i <= ELEMENTS; ++i) {
  7.                 for (j = i; (j-1) in ARRAY && ARRAY[j-1] > ARRAY[j]; --j) {
  8.                         temp = ARRAY[j]
  9.                         ARRAY[j] = ARRAY[j-1]
  10.                         ARRAY[j-1] = temp
  11.                 }
  12.         }
  13.         return
  14.   }
  15.   function gen_radom(NUM, TOPNUM, i, j, res, pick) {
  16.         for (i = 1; i <= NUM; ++i) {
  17.                 do {
  18.                         res = 1 + int(rand() * TOPNUM)
  19.                 } while (res in pick)
  20.                 pick[res] = res
  21.         }
  22.         j = 1
  23.         for (i in pick)
  24.                 radom[j++] = pick[i]
  25.   }
  26.   BEGIN {
  27.         srand('"$RANDOM"')
  28.         if (type == "6+1") {
  29.                 gen_radom(6, 33); sort(radom, 6)
  30.                 for (i = 1; i <= 6; ++i)
  31.                         printf("%02d ", radom[i])
  32.                 printf(" %d\n", 1 + int(rand() * 16))
  33.         } else if (type == "3d") {
  34.                 #gen_radom(3, 10);
  35.                 for (i = 1; i <= 3; ++i)
  36.                         printf("%2d ", int(rand() * 10))
  37.                 print
  38.         } else if (type == "7") {
  39.                 gen_radom(7, 35); sort(radom,7)
  40.                 for (i = 1; i <= 7; ++i)
  41.                         printf("%02d ", radom[i])
  42.                 print
  43.         }
  44.   }'
  45. }

  46. PS3='mai na ge? : '
  47. select var in "shuang se qiu" "3D" "35 xuan 7" "exit"
  48. do
  49.     case $var in
  50.         sh*)
  51.                 caipiao "6+1";;
  52.         3D)
  53.                 caipiao "3d";;
  54.         35*)
  55.                 caipiao "7";;
  56.         exit)
  57.                 exit;;
  58.         *)
  59.                 echo "no this option!";;
  60.     esac
  61. done

阅读(1360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~