| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.utils.fillertext.provider; |
| |
| import java.util.Random; |
| |
| public class BaseProvider { |
| |
| private final Random fRandom; |
| |
| public BaseProvider() { |
| fRandom = new Random(); |
| } |
| |
| public boolean trueOrFalse() { |
| return fRandom.nextBoolean(); |
| } |
| |
| public int randomBetween(int min, int max) { |
| int range = max - min + 1; |
| int randomInt = range > 0 ? fRandom.nextInt(range) : 0; |
| return min + randomInt; |
| } |
| |
| public long randomBetween(long min, long max) { |
| long range = (max - min) + 1; |
| return min + (long) (fRandom.nextDouble() * range); |
| } |
| |
| public double randomBetween(double min, double max) { |
| double range = max - min; |
| double randomDouble = range > 0 ? fRandom.nextDouble() * range : 0; |
| return min + randomDouble; |
| } |
| |
| public String numerify(String numberString) { |
| String result = ""; |
| for (int i=0; i < numberString.length(); i++) { |
| if (numberString.charAt(i) == '#') { |
| result += '0'+randomBetween(0, 9); |
| } |
| else { |
| result += numberString.charAt(i); |
| } |
| } |
| return result; |
| } |
| } |