Package ch.epfl.cs107.play.math.random
Class RandomEvent
java.lang.Object
ch.epfl.cs107.play.math.random.RandomEvent
Random Event implement notion of Bernoulli experiment with probability p of success
-
Constructor Summary
ConstructorsConstructorDescriptionRandom Constructor for Bernoulli experiment (i.e p is selected randomly) Notice: the random event can happen multiple timesRandomEvent(float p) Default Bernoulli Experiment Constructor Notice: by default the event can happen multiple timesRandomEvent(float p, boolean onlyOnce) Extended Bernoulli Experiment Constructor -
Method Summary
-
Constructor Details
-
RandomEvent
public RandomEvent(float p) Default Bernoulli Experiment Constructor Notice: by default the event can happen multiple times- Parameters:
p- (float): the probability of success
-
RandomEvent
public RandomEvent(float p, boolean onlyOnce) Extended Bernoulli Experiment Constructor- Parameters:
p- (float): the probability of successonlyOnce- (boolean): Specify if event can happen only once
-
RandomEvent
public RandomEvent()Random Constructor for Bernoulli experiment (i.e p is selected randomly) Notice: the random event can happen multiple times
-
-
Method Details
-
happend
public boolean happend()Run the Bernoulli experiment and return if it succeed- Returns:
- (boolean): true if the experiment succeed, false otherwise
-
nextInt
public int nextInt(int min, int max) Random integer generator tool: Generate an int between the two given bounds- Parameters:
min- (int): Low bound, inclusivemax- (int): High bound, exclusive- Returns:
- (int): between [min, max)
-