Skip to content

Instantly share code, notes, and snippets.

@skuenzli
Last active April 23, 2017 00:10
Show Gist options
  • Select an option

  • Save skuenzli/62b3e63bafb8b99d6d0a288065aceaab to your computer and use it in GitHub Desktop.

Select an option

Save skuenzli/62b3e63bafb8b99d6d0a288065aceaab to your computer and use it in GitHub Desktop.
A script to help pick the planks for the Giles baby room
#!/usr/bin/env bash
num_planks=${1:-1} #set default number of planks to pick to 1, specify whatever number you like as argument
declare -a colors=('white' 'natural' 'blue' 'red' 'gray' 'brown')
function pick_color(){
local color_idx=$(expr $RANDOM % ${#colors[@]})
echo "${colors[$color_idx]}"
}
for i in `seq 1 ${num_planks}`
do
color=$(pick_color)
echo "${color}"
done;
@skuenzli
Copy link
Author

# pick one plank
kermit:tmp skuenzli$ ./plank-picker.sh
blue

# pick 10 planks!
kermit:tmp skuenzli$ ./plank-picker.sh 10
white
brown
natural
white
brown
natural
natural
natural
gray
blue

@skuenzli
Copy link
Author

note, this script will not produce perfectly-uniform results, but is probably good enough for a baby room:

kermit:tmp skuenzli$ ./plank-picker.sh 6000 | sort | uniq -c | sort -nr
1041 white
1003 brown
1002 natural
 990 blue
 988 red
 976 gray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment