Random generation of numbers and letters from the Java base

Source: Internet
Author: User
Tags control characters

ASCII code for letters and numbers

The most widely used character set and its encoding in the current computer are ASCII codes developed by the United States National Standards Agency (ANSI) (American Standard Code for information interchange, US Standards Information Interchange Code), It has been established as an international standard by the International Organization for Standardization (ISO), known as ISO 646. Applies to all Latin letters, ASCII code has 7-bit code and 8-bit code two forms.
     because 1-bit binary numbers can represent (21=) 2 states: 0, 1, and 2-bit binary numbers can represent (22) = 4 states: 00, 01, 10, 11, and so on, 7-bit binary numbers can be represented (27= ) 128 states, each of which is uniquely compiled into a 7-bit binary code, corresponding to a character (or control code), which can be arranged in a decimal sequence number 0~127. Therefore, the 7-bit ASCII code is encoded with a seven-bit binary number, which can represent 128 characters.
     No. 0 to 32nd and 127th (total 34) are control characters or communication-specific characters, such as: LF (line feed), CR (carriage return), FF (page feed), DEL (delete), BEL (ringing), etc. Communication special Characters: SOH (text head), EOT (end), ACK (confirmation), etc.
     33rd to 126th (Total 94) is a character, where 48th to 57th is 0~9 10 Arabic numerals The 65~90 number is 26 uppercase English letters, the 97~122 number is 26 lowercase English letters, the remainder is some punctuation marks, arithmetic symbols and so on.
     Note: In the computer's storage unit, an ASCII value occupies one byte (8 bits) and its highest bit (B7) is used as the parity bit. The so-called parity check, refers to the code in the process used to verify whether there is a method of error, the general sub-parity check and parity two. Odd check rules: The correct code in one byte of the number of 1 must be odd, if not odd, the highest bit B7 Tim 1; Parity rule: The correct code in a byte of 1 must be an even number, if not even, the highest bit B7 add 1.  
     for ease of query, the following ASCII code table: common ASCII code matrix

ASCII code Keyboard ASCII Code Keyboard ASCII Code Keyboard ASCII Code Keyboard
27 Esc 32 SPACE 33 ! 34 "
35 # 36 $ 37 % 38 &
39 40 ( 41 ) 42 *
43 + 44 45 - 46 .
47 / 48 0 49 1 50 2
51 3 52 4 53 5 54 6
55 7 56 8 57 9 58 :
59 ; 60 < 61 = 62 >
63 ? 64 @ 65 A 66 B
67 C 68 D 69 E 70 F
71 G 72 H 73 I 74 J
75 K 76 L 77 M 78 N
79 O 80 P 81 Q 82 R
83 S 84 T 85 U 86 V
87 W 88 X 89 Y 90 Z
91 [ 92 \ 93 ] 94 ^
95 _ 96 ` 97 A 98 B
99 C 100 D 101 E 102 F
103 G 104 H 105 I 106 J
107 K 108 L 109 M 110 N
111 O 112 P 113 Q 114 R
115 S 116 T 117 U 118 V
119 W 120 X 121 Y 122

Z

123 { 124 | 125 } 126 ~

Use this principle to write useful small examples

ImportJava.util.Random; Public classStringrandom {//generate random numbers and letters,     PublicString Getstringrandom (intlength) {String Val= ""; Random Random=NewRandom (); //parameter length, which indicates the generation of several random numbers         for(inti = 0; i < length; i++) {String charornum= Random.nextint (2)% 2 = = 0? "Char": "Num"; //output letters or numbers            if("Char". Equalsignorecase (Charornum)) {                //Whether the output is in uppercase or lowercase letters                inttemp = random.nextint (2)% 2 = = 0? 65:97; Val+= (Char) (Random.nextint (26) +temp); } Else if("Num". Equalsignorecase (Charornum)) {Val+ = string.valueof (Random.nextint (10)); }        }        returnVal; }         Public Static voidMain (string[] args) {stringrandom test=NewStringrandom (); //TestSystem.out.println (Test.getstringrandom (8)); }}

Random generation of numbers and letters from the Java base

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.