/*
 *  Copyright 2011 Eric F. Savage, code@efsavage.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.ajah.util;

import java.util.List;
import java.util.Random;

/**
 * Utilities for creating random data.
 * 
 * @author Eric F. Savage <code@efsavage.com>
 */
public class RandomUtils {

	private static Random random = new Random();

	/**
	 * Returns a random number between the from and to parameters.
	 * 
	 * @see Random#nextDouble()
	 * @param from
	 *            The lowest allowable number.
	 * @param to
	 *            The highest allowable number.
	 * @return Random number between from and to.
	 */
	public static long getRandomNumber(final long from, final long to) {
		return from + (long) (random.nextDouble() * (to - from));
	}

	/**
	 * Returns a random number between the from and to parameters.
	 * 
	 * @see Random#nextDouble()
	 * @param from
	 *            The lowest allowable number.
	 * @param to
	 *            The highest allowable number.
	 * @return Random number between from and to.
	 */
	public static int getRandomNumber(final int from, final int to) {
		return from + (int) (random.nextDouble() * (to - from));
	}

	/**
	 * Returns a random element from a list.
	 * 
	 * @param <T>
	 *            Type of element.
	 * @param list
	 *            The list to find a random element in.
	 * @return A random element from the list, or null if the list is null or
	 *         empty.
	 */
	public static <T> T getRandomElement(final List<T> list) {
		if (CollectionUtils.isEmpty(list)) {
			return null;
		}
		return list.get(getRandomNumber(0, list.size()));
	}

}

@@ -1645,16 +1645,26 @@
 + (int) 
+Math.floor
 (random.
@@ -1670,35 +1670,41 @@
 .nextDouble() * 
+(
 (to
+ + 1)
  - from));%0A%09%7D%0A%0A%09
@@ -2144,10 +2144,286 @@
 ));%0A%09%7D%0A%0A
+%09public static String getRandomAlphaString(int minLength, int maxLength) %7B%0A%09%09char%5B%5D chars = new char%5BgetRandomNumber(minLength, maxLength)%5D;%0A%09%09for (int i = 0; i %3C chars.length; i++) %7B%0A%09%09%09chars%5Bi%5D = (char) ('a' + getRandomNumber(0, 26));%0A%09%09%7D%0A%09%09return String.valueOf(chars);%0A%09%7D%0A
 %7D%0A

Add getRandomAlphaString method, fix getRandomNumber