io.mstream.trader.simulation.repository.RandomGenerator Maven / Gradle / Ivy
package io.mstream.trader.simulation.repository;
import io.mstream.trader.commons.utils.repository.MultipleRepository;
import rx.Observable;
import rx.Single;
import java.util.Random;
public abstract class RandomGenerator {
private final MultipleRepository repository;
private final Random random;
protected RandomGenerator(MultipleRepository repository, Random random) {
this.repository = repository;
this.random = random;
}
public Single getRandom() {
return getRandom(0);
}
public Single getRandom(int upperBoundOffset) {
return repository
.getAll()
.toList()
.flatMap(elements ->
Observable.just(
elements.get(
random.nextInt(
elements.size() -
upperBoundOffset
)
)
)
)
.toSingle();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy