mardi 30 juin 2015

Setting up a Piecewise Distribution in C++

After hours of struggling with this issue, I cannot find any explanations for my error.

I want the computer to pick a random number (weighted) between 0 and 120 (inclusive). I have an array, interval[], which holds the numbers from 0 to 120 (inclusive). I have another array, weights[], which holds the probabilities for choosing the ith element in the array. I want to define a probability distribution function for these data. I am trying to write:

piecewise_constant_distribution<> dist(begin(interval), end(interval), begin(weights));

However, I get an error saying: "invalid probability vector for discrete_distribution". Can someone please help me with this?




Aucun commentaire:

Enregistrer un commentaire