How to generate random numbers(chars) in linux shell script
By:Roy.LiuLast updated:2021-02-03
In this article, we’ll learn how to generate random numbers or chars in linux shell script.
1. Environment
Centos7_x64
2. Generating random numbers in linux shell scripts.
We can get a random 8-bit number by one of the following three methods scripts.
2.1. Use $RANDOM:
echo $RANDOM | cksum |cut -c 1-8
2.2. Use openssl:
openssl rand -base64 4 |cksum |cut -c 1-8
2.3. Use date:
date +%N | cut -c 1-8
Output figure
3. Generating random chars in linux shell scripts.
We can get a random 8-bit char by one of the following three methods scripts.
3.1. Use $RANDOM
echo $RANDOM | md5sum | cut -c 1-8
3.2. Use openssl
openssl rand -base64 6
3.3. Use UUID
cat /proc/sys/kernel/random/uuid | cut -c 1-8
Output figure
From:Is Everything OK
Previous: None
COMMENTS