Here you can find the source of randomText(int length)
Parameter | Description |
---|---|
length | a parameter |
public static String randomText(int length)
//package com.java2s; //License from project: Open Source License public class Main { /**//w ww . j a va2s . co m * Create a random string with upper and lower case latin letters, * spaces and paragraphs. * @param length * @return */ public static String randomText(int length) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { sb.append(randomChar()); } return sb.toString(); } private static char randomChar() { int num = (int) Math.floor(Math.random() * 60); if (num < 26) return (char) ((int) 'a' + num); num -= 26; if (num < 26) return (char) ((int) 'A' + num); num -= 26; if (num < 1) return '\n'; return ' '; } }