-
-
Save koreyou/c10597aa9744978a078d108ee369728d to your computer and use it in GitHub Desktop.
Linux shuf command with seed option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# seeding adopted from https://stackoverflow.com/a/41962458/7820599 | |
get_seeded_random() | |
{ | |
seed="$1"; | |
openssl enc -aes-256-ctr -pass pass:"$seed" -nosalt \ | |
</dev/zero 2>/dev/null; | |
} | |
seed=0; | |
# Option parsing adopted from https://stackoverflow.com/a/14203146 | |
REST="" | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-s) | |
seed="$2" | |
shift | |
shift | |
;; | |
*) # unknown option | |
REST="$REST $1" | |
shift # past argument | |
;; | |
esac | |
done | |
shuf --random-source=<(get_seeded_random $seed) $REST | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment