001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.text; 018 019/** 020 * TextRandomProvider implementations are used by {@link RandomStringGenerator} 021 * as a source of randomness. It is highly recommended that the 022 * <a href="https://commons.apache.org/proper/commons-rng/">Apache Commons RNG</a> 023 * library be used to provide the random number generation. 024 * 025 * <p> 026 * When using Java 8 or later, TextRandomProvider is a functional interface and 027 * need not be explicitly implemented. For example: 028 * </p> 029 * <pre> 030 * {@code 031 * UniformRandomProvider rng = RandomSource.create(...); 032 * RandomStringGenerator gen = RandomStringGenerator.builder() 033 * .usingRandom(rng::nextInt) 034 * // additional builder calls as needed 035 * .build(); 036 * } 037 * </pre> 038 * @since 1.1 039 */ 040public interface TextRandomProvider { 041 042 /** 043 * Generates an int value between 0 (inclusive) and the specified value 044 * (exclusive). 045 * @param max Bound on the random number to be returned. Must be positive. 046 * @return a random int value between 0 (inclusive) and n (exclusive). 047 */ 048 int nextInt(int max); 049}