P
P
Proshka172019-02-11 23:02:24
Python
Proshka17, 2019-02-11 23:02:24

How to solve a programming problem?

Good afternoon! I can't figure out how to solve the following programming problem:

Write a program that from a random Bernoulli variable with p = q = 0.5 and simple
mathematical operations one could obtain a random Bernoulli variable with
any given p ∈ [0,1].

The problem is not in the implementation (I have not reached it yet), but in how to represent the probability distribution in a programming language?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-02-11
@sergiks

Let's say you have a function that returns a random number between 0 and 1 with equal probability.
And you need to get heads or tails with a probability of heads of 60%
It's simple: get a random number from 0 to 1 and compare with 0.6
Get < 0.6 probability 60 %, more than 40%.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question