Java Random Long generateRandomBySampleSeed(long sampleSeed, long fallbackValue)

Here you can find the source of generateRandomBySampleSeed(long sampleSeed, long fallbackValue)

Description

Generate random instance according to sample seed.

License

Apache License

Parameter

Parameter Description
sampleSeed sample seed to generate Random instance
fallbackValue sample seed fall back value

Return

Random instance according to the sample seed value If the sample seed value not equal to fallbackValue, then will use it to generate Random instance. Else take fallback measure: generate Random instance without given seed.

Declaration

public static Random generateRandomBySampleSeed(long sampleSeed, long fallbackValue) 

Method Source Code

//package com.java2s;
/**/*w  w w . j a va  2 s. c  o  m*/
 * Copyright [2012-2014] PayPal Software Foundation
 *
 * 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.
 */

import java.util.*;

public class Main {
    /**
     * Generate random instance according to sample seed.
     * 
     * @param sampleSeed
     *            sample seed to generate Random instance
     * @param fallbackValue
     *            sample seed fall back value
     * @return Random instance according to the sample seed value
     *         If the sample seed value not equal to fallbackValue, then will use it to generate Random instance.
     *         Else take fallback measure: generate Random instance without given seed.
     */
    public static Random generateRandomBySampleSeed(long sampleSeed, long fallbackValue) {
        if (sampleSeed != fallbackValue) {
            return new Random(sampleSeed);
        }
        return new Random();
    }
}

Related

  1. generateRandomLongValue()
  2. getLong()
  3. getLong()
  4. getLongBetween(long n, long m)