Answer the question
In order to leave comments, you need to log in
Change the probability of numbers falling out?
I am taking my first steps in learning python. Installed the numPy module.
I display any random number up to 100 using
Question: Is it possible to make it so that the probability of outputting values from 0 to 50 is higher than from 50 to 100?
I would be grateful if you write in the direction of what to look for, maybe you will throw off any source where this process will be described in detail.
np.random.randint(100, size=1)
Answer the question
In order to leave comments, you need to log in
You need to look at the result of rand as a certain number, the probability of which is 1 / N. And for your real number to come up twice as often, its probability must be equal to these two numbers 2 * (1 / N).
In your example, the probability of any number coming up is 1 / 100, so that for numbers from 0 to 50 the probability is, for example, 2 / N, you need them to occupy two numbers from the result of randint.
rand = np.random.randint(150, size=1)[0]
if rand < 100:
res = rand // 2
else:
res = rand - 50
Start by "looking" towards probability theory. To start. There are hundreds and thousands of sources on the net.
Now about your question.
You have taken the UNIFORM distribution. And generate numbers. Functions for generating numbers according to the basic law of distribution are indeed implemented in Python/numpy. If you want to generate numbers with a certain distribution that you yourself set, nothing prevents you from doing this. For example, taking the same uniform distribution as a basis and performing the transformation according to the distribution density formula, which you yourself will write.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question