How to extract element with weight

Hi everyone,
If i have a vector, for example
A=c(1:1000)

and i need to extract only one element, but i want that the probability to extract a little number is very very bigger than the probability to extract a big number, for example I want that this probability is more or less like an exponential probability, how i can do that?

I need to give a hight weight to lower number and low weight to bigger number, but how i can do that?

thank you

perhaps something along these lines

A=c(1:1000)
(w <- exp(-A))
(sum_w <- sum(w))
(norm_w<- w/sum_w)

sample(A,size=1,prob=norm_w)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.