How the shell generates random numbers

Source: Internet
Author: User


Method 1: Use/dev/urandom

[[email protected] shell]# tr -dc  "0-9"   < /dev/urandom | head -c 10        # Generate 10 Digital 5798734885[[email protected] shell]# [[email protected] shell]# [[email  protected] shell]# tr -dc  "A-Z"  < /dev/urandom | head -c  10         #生成10个小写字符xxcudpzyfu [[Email protected] shell ]# [[email protected] shell]# tr -dc  "A-Z"  < /dev/urandom |  head -c 10         #生成10个大写字符XFDBEFCDKV [[email  protected] shell]# [[email protected] shell]# tr -dc  "0-9,a-z"  <  /dev/urandom | head -c 10   #生成数字和字符的组合ryjhjhnpyd [[email protected]  shell]# 


Method Two: Use Date +%s


    1. Randomly generate a bunch of numbers

[Email protected]:/home/dell/shell# date +%s |cksum |cut-d ""-F 1 1934689009

Expansion: Randomly generates a number within 10

[Email protected]:/home/dell/shell# echo "' Date +%s |cksum |cut-d" "-F 1 '%100" |bc81

2. Randomly generate a string of lowercase letters

[Email protected]:/home/dell/shell# Date +%s| md5sum | Tr-dc "A-Z" |head-c 10[email protected]:/home/dell/shell#


3. Randomly generated combinations of numbers and letters

[Email protected]:/home/dell/shell# Date +%s| md5sum | Head-c 1067e


Method Three: Using OpenSSL rand

[Email protected]:/home/dell/shell# OpenSSL rand-base64 40c6s7wofbx3s4imkzb9mhdkcywzyreae0lauqplpcaex+kf8hakxorw==


This article is from the "Hello World" blog, so be sure to keep this source http://237085.blog.51cto.com/227085/1959461

How the shell generates random numbers

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.