Python random.choice. I'd like to ask you one more question.

Asked 2 years ago, Updated 2 years ago, 17 views

I know that you use random.choice (list, probability, cumulative probability, number of draws). We don't need a cumulative probability right now.

The purpose of the choices function is to make the values that are more likely to be selected in the list more often, right? But I want to make sure that the most likely value is the least likely value and the least likely value is the best. You can put the value of weights in reverse, but the current value of weights changes randomly every time you run it, so we can't set the value in advance.

It doesn't matter as long as the purpose is implemented, even if it's not a choices function.

Is there any way?

python

2022-09-22 14:28

1 Answers

The weights value should not change to "random" at each run.

You have to make the weight of the smaller value larger.

The randomly selected value is [1, 2, 3, 4, 5] Let's say that. (You said you'd pick 20, but let's just say you pick 5.)

You're saying that you want to have the biggest chance of getting 1.

[w(1), w(2), w(3), w(4), w(5)] We're going to make weights, and w(1) is going to be the largest.

It's up to the person who asked me how to determine the function w.

def w(n) : return 1/n If you say so, weights are [ 1/1, 1/2, 1/3, 1/4, 1/5 ] That's what happens.

def w(n): return 1000 - 1 and becomes weights. [ 999, 998, 997, 996, 995 ]

OK?


2022-09-22 14:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.