Some thinking analysis of generating random numbers in Linux shell _linux

Source: Internet
Author: User
Tags current time uuid

1. Use of time-related random numbers

Generate output Unixtimestamp (%s) and current time nanosecond data (%N, accurate to one-seconds) using the data command. )

The former ensures that the output does not repeat in different seconds, and that the number does not repeat in the same second and that the combination is possible.

Copy Code code as follows:

Date +%s%n

This method does not rely on the system as long as the time does not stop, it can always get a random number without repetition

2. System Shell Internal variable $RANDOM

So there's nothing to say about relying on the shell

3. Obtain and then calculate checksum via Linux's random device

Copy Code code as follows:

Head-10/dev/urandom | Cksum

Note that there is no use of cat to get this is an endless road to get 1 rows and 10 lines There's not much difference between this

4. Through the kernel of the Linux UUID access

The data of the UUID will be added to the hardware, time, and the current running information of the machine, which can guarantee the generation of the world's only direct

Copy Code code as follows:

Cat/proc/sys/kernel/random/uuid

You can then convert the checksum to the number, but rely on the Linux kernel.

4 kinds of ideas for your own reference.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.