Skip to content

Instantly share code, notes, and snippets.

@deven96
Last active March 19, 2021 12:47
Show Gist options
  • Select an option

  • Save deven96/e4c292562a7c3a58f9fdd1d2f8f8fd22 to your computer and use it in GitHub Desktop.

Select an option

Save deven96/e4c292562a7c3a58f9fdd1d2f8f8fd22 to your computer and use it in GitHub Desktop.

Revisions

  1. deven96 revised this gist Mar 19, 2021. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions selectRandomExcuse.bash
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # Seed random generator
    # Generate a random number using date
    RANDOM=$(date +%s)
    EXCUSESARRAY=(
    "to visit Nosarobumeh in the hospital"
    @@ -10,7 +10,11 @@ EXCUSESARRAY=(
    "for a bit to run some errands"
    )

    # this sets the $randomExcuse variable

    # Sets the $randomExcuse variable
    function selectRandomExcuse {
    # To get the length of an array e.g EXCUSES in bash, we use ${#arrayName[@]}
    # so $RANDOM % (length of array) gives us a number from 0 - length of array
    # which we then use to index from the EXCUSESARRAY
    randomExcuse=${EXCUSESARRAY[$RANDOM % ${#EXCUSESARRAY[@]} ]}
    }
  2. deven96 revised this gist Mar 19, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion selectRandomExcuse.bash
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,9 @@ EXCUSESARRAY=(
    "to take a rest"
    "for the next one hour"
    "for a bit to run some errands"
    )
    )

    # this sets the $randomExcuse variable
    function selectRandomExcuse {
    randomExcuse=${EXCUSESARRAY[$RANDOM % ${#EXCUSESARRAY[@]} ]}
    }
  3. deven96 created this gist Mar 19, 2021.
    11 changes: 11 additions & 0 deletions selectRandomExcuse.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash
    # Seed random generator
    RANDOM=$(date +%s)
    EXCUSESARRAY=(
    "to visit Nosarobumeh in the hospital"
    "for some away screen time"
    "as I have a slight headache"
    "to take a rest"
    "for the next one hour"
    "for a bit to run some errands"
    )