[Linux] Random number generation

insert image description here

Generate a random number: the default is (0-32767)

echo $RANDOM

insert image description here

Generate a random number in the specified interval: randomly generate a number between 1-50

echo $((RANDOM%50+1))

insert image description here

Randomly generate timestamp seconds and nanoseconds encryption operations

date +%s%N | md5sum

insert image description here

Generate a random character to specify 10 in the use of md5sum check

head -c 10 /dev/random |md5sum

insert image description here

What is /dev/random?

/dev/random is a random number generator device file used to generate high-quality random numbers. It generates random numbers by collecting environmental noise on the system such as hardware noise, disk activity, etc. Since it can only generate random numbers when there is enough ambient noise on the system, the random numbers generated by /dev/random are of high quality.

However, the main disadvantage of /dev/random is that if there is not enough ambient noise on the system, it will cause random number generation to slow down, and sometimes stop altogether. This may cause some applications to not work properly because they require large numbers of random numbers.

Generate random UUID

UUID, universal unique identifier.
Let all elements of the distributed system have unique identification information.

uuidgen
cat /proc/sys/kernel/random/uuid

insert image description here

Encryption Algorithm

md5 message digest algorithm –> verify the integrity of the file
md5sum [file name]

echo "123" | md5sum

CRC Cyclic Redundancy Check Code –>sksum
echo “123” | sksum

insert image description here

related articles

article title Article link
[Linux] Centos7 randomly generates passwords https://liucy.blog.csdn.net/article/details/129922682
[Linux] Random number generation https://liucy.blog.csdn.net/article/details/130387463

Guess you like

Origin blog.csdn.net/liu_chen_yang/article/details/130387463
Recommended