RandomSequenceGenerator { public double computeNextNumber(double previous) { double range = (max - min) / 20; double scaled = (random.nextDouble() - 0.5 + bias) * range; double shifted = previous + scaled; if (shifted < min || shifted > max) { shifted = previous - scaled; bias = -bias; } shifted = ((Long)Math.round(shifted * 10000)).doubleValue() /10000; return shifted; } RandomSequenceGenerator(double min, double max); Observable<Double> create(long interval, TimeUnit timeUnit); Observable<Integer> createIntegerSequence(long interval, TimeUnit timeUnit); double computeNextNumber(double previous);  }
@Test public void should_generate_a_bounded_number() { double min = 3.14; double max = 5.42; RandomSequenceGenerator generator = new RandomSequenceGenerator(min, max); double next = generator.computeNextNumber(4); assertThat(next).isBetween(min, max); }
@Test public void should_generate_a_bounded_number_close_to_previous() { double min = 3; double max = 5; RandomSequenceGenerator generator = new RandomSequenceGenerator(min, max); int previous = 4; double next = generator.computeNextNumber(previous); assertThat(next).isBetween(previous - (max-min)/10, previous + (max-min)/10); }
@Test public void should_generate_a_number_with_a_limited_number_of_digits() { double min = 3; double max = 5; RandomSequenceGenerator generator = new RandomSequenceGenerator(min, max); int previous = 4; Double next = generator.computeNextNumber(previous); assertThat(next.toString().length()).isLessThan(7); }