random cards


SUBMITTED BY: foxhunters

DATE: Aug. 8, 2016, 12:17 a.m.

FORMAT: Text only

SIZE: 701 Bytes

HITS: 8259

  1. #!/bin/bash
  2. # pick-card.sh
  3. # This is an example of choosing random elements of an array.
  4. # Pick a card, any card.
  5. Suites="Clubs
  6. Diamonds
  7. Hearts
  8. Spades"
  9. Denominations="2
  10. 3
  11. 4
  12. 5
  13. 6
  14. 7
  15. 8
  16. 9
  17. 10
  18. Jack
  19. Queen
  20. King
  21. Ace"
  22. # Note variables spread over multiple lines.
  23. suite=($Suites) # Read into array variable.
  24. denomination=($Denominations)
  25. num_suites=${#suite[*]} # Count how many elements.
  26. num_denominations=${#denomination[*]}
  27. echo -n "${denomination[$((RANDOM%num_denominations))]} of "
  28. echo ${suite[$((RANDOM%num_suites))]}
  29. # $bozo sh pick-cards.sh
  30. # Jack of Clubs
  31. # Thank you, "jipe," for pointing out this use of $RANDOM.
  32. exit 0

comments powered by Disqus