ChapterFivePartIII

Random intz inta 1 case study generating

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nd (int)'z' is (int)((int)'a' + Math.random() * ((int)'z' - (int)'a' + 1) Case Study: Generating Random Characters, cont. As discussed in Section 2.9.4, all numeric operators can be applied to the char operands. The char operand is cast into a number if the other operand is a number or a character. So, the preceding expression can be simplified as follows: 'a' + Math.random() * ('z' - 'a' + 1) So a random lowercase letter is (char)('a' + Math.random() * ('z' - 'a' + 1)) Case Study: Generating Random Characters, cont. To generalize the foregoing discussion, a random character between any two characters ch1 and ch2 with ch1 < ch2 can be gen...
View Full Document

This note was uploaded on 01/26/2012 for the course IT 108, 103, taught by Professor Bruno during the Spring '11 term at George Mason.

Ask a homework question - tutors are online