Skip to content

Instantly share code, notes, and snippets.

@s1037989
Created November 6, 2025 01:11
Show Gist options
  • Select an option

  • Save s1037989/233aac66589be102bb3351ce7a4987f0 to your computer and use it in GitHub Desktop.

Select an option

Save s1037989/233aac66589be102bb3351ce7a4987f0 to your computer and use it in GitHub Desktop.
bash random number generator
# Source - https://stackoverflow.com/questions/1194882/how-to-generate-random-number-in-bash
# Posted by s1037989
# Retrieved 2025-11-05, License - CC BY-SA 4.0
rand() {
perl -E '$ARGV[0]||=""; $ARGV[0]=int($ARGV[0])||length($ARGV[0]); say join "", int(rand(9)+1)*($ARGV[0]?1:0), map { int(rand(10)) } (0..($ARGV[0]||0)-2)' $1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment