The question is related to bash, Linux like Ubuntu, /dev/random and /dev/urandom .
How to generate a random number in a range which can be positive or negative, by /dev/urandom on bash ?
Known are:
- /dev/urandom generate more random numbers than random.
- Differents of /dev/random and /dev/urandom are: https://www.2uo.de/myths-about-urandom/
- https://heitorpb.github.io/bla/2020/04/07/bash-random-numbers/
Follow are a sample for a not searched solution to do it in a range on bash, by not searched function "RANDOM" and only in a positive range.
min=1
max=1000
rnd_count=$(( RANDOM % ( max - min + 1 ) + min ))
echo $rnd_count
A partly solution is to generate a random number by bash random or urandom on positive range works on follow way, how to do this on positive and negative range too, is unknown fo me. And its not pure bash. A pure bash solution are wanted.
echo "$(od -An -N4 -tu4 /dev/urandom) % 15 + 1" | bc
min=1; max=1000; rnd_count=$((RANDOM%($max-$min+1)+$min)); echo $rnd_count
and it gives a different number each time. Again, we are not here to teach you how to do it, but we are here to help in a Q&A style if you get stuck on something.