Code Examples
A repository of 155 code examples for BeepBeep
RandomMutator.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package plots;
19 
20 import java.util.Random;
21 
22 import ca.uqac.lif.cep.ProcessorException;
23 import ca.uqac.lif.cep.UniformProcessor;
24 
25 /**
26  * Processor that converts any input into a random integer. This
27  * processor is represented graphically as follows:
28  * <p>
29  * <img src="./doc-files/plots/RandomMutator.png" alt="Processor">
30  * @author Sylvain HallĂ©
31  */
32 public class RandomMutator extends UniformProcessor
33 {
34  /**
35  * A Random object
36  */
37  protected Random m_random;
38 
39  /**
40  * The minimum random number that can be generated
41  */
42  protected int m_minValue = 0;
43 
44  /**
45  * The minimum random number that can be generated
46  */
47  protected int m_maxValue = 0;
48 
49  public RandomMutator(int min_value, int max_value)
50  {
51  super(1, 1);
52  m_random = new Random();
53  m_minValue = min_value;
54  m_maxValue = max_value;
55  }
56 
57  @Override
58  protected boolean compute(Object[] inputs, Object[] outputs) throws ProcessorException
59  {
60  outputs[0] = m_random.nextInt(m_maxValue - m_minValue) + m_minValue;
61  return true;
62  }
63 
64  @Override
65  public RandomMutator duplicate(boolean with_state)
66  {
67  return new RandomMutator(m_minValue, m_maxValue);
68  }
69 }
Processor that converts any input into a random integer.
int m_maxValue
The minimum random number that can be generated.
int m_minValue
The minimum random number that can be generated.
Random m_random
A Random object.