def bernoulliDistribution(request):
    form = BernoulliDistributionForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            random_variable = DiscreteRandomVariable(BernoulliDistribution(form.cleaned_data["probability"]))
            result = random_variable.getPossibleValue()
        else:
            error_message = Constants.INCORRECT_INPUT
    return TemplateResponse(request, "discrete_distributions/bernoulli_distribution.html", locals())
def geometricDistribution(request):
    form = GeometricDistributionForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            probability = form.cleaned_data["probability"]
            sample = []
            while True:
                random_variable = DiscreteRandomVariable(BernoulliDistribution(probability))
                value = random_variable.getPossibleValue()
                sample.append(value)
                if value == 1:
                    break
            count = len(sample)
            sample = enumerate(sample)
        else:
            error_message = Constants.INCORRECT_INPUT
    return TemplateResponse(request, "discrete_distributions/geometric_distribution.html", locals())
def negativeBinomialDistribution(request):
    form = NegativeBinomialDistributionForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            probability = form.cleaned_data["probability"]
            r = form.cleaned_data["r"]
            successful = 0
            sample = []
            while successful < r:
                random_variable = DiscreteRandomVariable(BernoulliDistribution(probability))
                value = random_variable.getPossibleValue()
                if value == 1:
                    successful += 1
                sample.append(value)
            count = len(sample)
            sample = enumerate(sample)
        else:
            error_message = Constants.INCORRECT_INPUT
    return TemplateResponse(request, "discrete_distributions/negative_binomial_distribution.html", locals())