- Home
- Contact
-
Articles / Code
- HTML/CSS (2)
-
Scripts (17)
- Twitter & bash
- Generate sitemaps
- random floating point in bash
- Gmail script
- Python http POST requests
- Bashrc enhancements
- commandline <> nautilus
- Word Definitions
- Synonyms
- mysqld monitor
- remote server
- links and emailaddresses
- Apache Analyser
- remote ipaddress
- OOP Python
- mysql tuning
- diskspace notification
- Server Configuration (6)
- ICT-security (2)
Random floating point in bash
» Articles / Code » Scripts » Random floating point in bash
While trying to to figure out a way to have a script slow down a little, I noticed that in order to use bash' 'sleep' function with values less then 1 second, you can simply use something like:
sleep .2
But trying to use a random value that gives values smaller then 1 second needs a little different approach:
First of all, $RANDOM returns a random integer. Then, to turn this into some random value like 0.0 , 0.1 , 0.2 you could use the module function '%'
echo "$RANDOM % .3 " |bc
And to make a combination of these two it would turn into
sleep $(echo "$RANDOM % .3 " |bc)