blob: d7b963426b38d77382315f1496839d91c5d2c249 [file] [log] [blame]
/**
*
* 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.xtext.entitymock.common.filler;
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) {
StringBuilder result = new StringBuilder();
for (int i=0; i < numberString.length(); i++) {
if (numberString.charAt(i) == '#') {
result.append(Character.forDigit(randomBetween(0, 9), 10));
}
else {
result.append(numberString.charAt(i));
}
}
return result.toString();
}
}