From dc5d24274c0898ad5cafecde98d486425663fc45 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Wed, 19 Apr 2023 14:43:45 +0200 Subject: [PATCH] Adds more RANDOM --- src/today.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/today.sh b/src/today.sh index a510d1fe..54babc29 100755 --- a/src/today.sh +++ b/src/today.sh @@ -84,17 +84,19 @@ VERSION_DIR="$DIR/../scripture/${VERSION}" # only load if not already given if [ -z "${TODAY_S_SCRIPTURE}" ]; then #████████████████████████████████████████████████████████████████ RANDOM ███ - # set a random temp file - sort -R -k1 -b "${SORTED}" >"${TMP}" - # get the first line - TODAY_S_SCRIPTURE=$(head -n 1 "${TMP}") - # only if not a test - if (("$DRY_RUN" == 0)); then - # remove the verse - sed -i -e '1,1d' "${TMP}" - # add to used verses - [ -f "${USED}" ] && echo "$TODAY_S_SCRIPTURE" >>"${USED}" || echo "$TODAY_S_SCRIPTURE" >"${USED}" - fi + # set a random temp file + sort -R -k1 -b "${SORTED}" >"${TMP}" + # get a random number between 1 and 1900 + RANDOM_LINE=$((RANDOM % 1900 + 1)) + # get the line corresponding to the random number + TODAY_S_SCRIPTURE=$(sed -n "${RANDOM_LINE}{p;q}" "${TMP}") + # only if not a test + if (("$DRY_RUN" == 0)); then + # remove the verse + sed -i -e "${RANDOM_LINE},${RANDOM_LINE}d" "${TMP}" + # add to used verses + [ -f "${USED}" ] && echo "$TODAY_S_SCRIPTURE" >>"${USED}" || echo "$TODAY_S_SCRIPTURE" >"${USED}" + fi #███████████████████████████████████████████████████ SIX MONTH RETENTION ███ # check test behaviour