You can use Uniform(0,1) to generate the random number on [0,1). You need to map the uniform random results to your probabilities to generate the number. One way to map is to compute the cumulative probability distribution. For example:

number: {4, 8, 3}

Prob: {0.2, 0.7, 0.1}

Cumulative Probability Distribution: {0.2, 0.9, 1}

Let x = uniform(0,1)

then

number = 4 if 0<= x<0.2

number = 8 if 0.2<=x<0.9

number = 3 if 0.9<=x<1

Thanks,

Paras

On Tuesday, November 28, 2017 at 1:23:28 PM UTC-8,

[hidden email] wrote:

Good night,

I have 20 numbers which have different probabilities of being selected. How can I randomly generate one number based on these probabilities?

Thank you!

Best regards,

Fernanda

--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.

To unsubscribe from this group and stop receiving emails from it, send an email to

[hidden email].

To post to this group, send email to

[hidden email].

Visit this group at

https://groups.google.com/group/ampl.

For more options, visit

https://groups.google.com/d/optout.