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 * <p>
021 * TextRandomProvider implementations are used by {@link RandomStringGenerator}
022 * as a source of randomness.  It is highly recommended that the
023 * <a href="http://commons.apache.org/proper/commons-rng/">Apache Commons RNG</a>
024 * library be used to provide the random number generation.
025 * </p>
026 *
027 * <p>
028 * When using Java 8 or later, TextRandomProvider is a functional interface and
029 * need not be explicitly implemented.  For example:
030 * </p>
031 * <pre>
032 * {@code
033 * UniformRandomProvider rng = RandomSource.create(...);
034 * RandomStringGenerator gen = new RandomStringGenerator.Builder()
035 *     .usingRandom(rng::nextInt)
036 *     // additional builder calls as needed
037 *     .build();
038 * }
039 * </pre>
040 * @since 1.1
041 */
042public interface TextRandomProvider {
043
044    /**
045     * Generates an int value between 0 (inclusive) and the specified value
046     * (exclusive).
047     * @param max  Bound on the random number to be returned. Must be positive.
048     * @return a random int value between 0 (inclusive) and n (exclusive).
049     */
050    int nextInt(int max);
051}