001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.propertyhelper; 016 017import java.security.SecureRandom; 018import java.util.Random; 019 020import com.google.common.base.Strings; 021 022public final class RandomUtil { 023 024 private RandomUtil() { 025 throw new AssertionError("RandomUtil can not be instantiated"); 026 } 027 028 public static Random createRandomFromSeed(String seedValue) { 029 String seedString = Strings.nullToEmpty(seedValue); 030 031 if (!seedString.isEmpty()) { 032 long value = 0L; 033 for (char c : seedString.toCharArray()) { 034 value ^= c; 035 value <<= 4L; 036 } 037 return new Random(value); 038 } else { 039 return new SecureRandom(); 040 } 041 } 042}