-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomPicker.sh
More file actions
executable file
·36 lines (31 loc) · 918 Bytes
/
Copy pathRandomPicker.sh
File metadata and controls
executable file
·36 lines (31 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# gl0bal01 - Random Picker Script
# -------------------------------
# Description:
# This script randomly selects an item from a list of items provided as input.
# It is useful for scenarios where you need to make a random choice from multiple options.
# Function to generate a random integer within a specified range
generate_random_int() {
local min=$1
local max=$2
local range=$((max - min + 1))
if ((range < 0)); then
echo "Error: Invalid range" >&2
exit 1
fi
random_int=$(od -An -N4 -tu4 /dev/urandom | tr -d ' ')
echo $((min + (random_int % range)))
}
# Check if at least two arguments are provided
if [[ $# -lt 2 ]]; then
echo "Usage: $0 <min> <max> [count]"
exit 1
fi
# Parse command line arguments
min=$1
max=$2
count=${3:-1}
# Generate and output random numbers
for ((i = 0; i < count; i++)); do
generate_random_int "$min" "$max"
done