文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Picking a random card from a deck

Picking a random card from a deck

时间:2006-07-17  来源:huanghaojie

 #!/bin/bash
 # pick-card.sh

 # This is an example of choosing random elements of an array.

 # Pick a card, any card.

 Suites="Clubs Diamonds Hearts Spades"

 Denominations="2 3 4 5 6 7 8 9 10 Jack Queen King Ace"

 # Note variables spread over multiple lines.

 suite=($Suites)                # Read into array variable.
 denomination=($Denominations)

 num_suites=${#suite[*]}        # Count how many elements.
 num_denominations=${#denomination[*]}

 echo -n "${denomination[$((RANDOM%num_denominations))]} of "
 echo ${suite[$((RANDOM%num_suites))]}

 # $bozo sh pick-cards.sh
 # Jack of Clubs
 # Thank you, "jipe," for pointing out this use of $RANDOM.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载