Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weighted Random Choice
#3
Thanks for your response! I didn't even think about IStringMap. That will be super helpful in for holding the array dictionary.

The end result was to have it only return one value.
I was giving an example of how often the result would appear with the 1/40. (2.5%) but wanted it to be dynamic so that if you added grapes to the list with a weight of 100, pear would go down to 1/140 (~0.7%)
I think you're onto something with summing them up. I'm just not sure how to do a RandomInt of the sum and get them to cooperate with their weights.

The super inefficient way would be to populate an array with each item a number of times equal to their weight, then pull a random line. That would make sure that pears would only be in the list once, apples would be in there nine times, and so on... so there would be a higher chance for RandomInt to pick apples than pears.

in python it would be:
random.choices([apple,pear,banana,orange],[9,1,10,20])

I was hoping to be able to recreate this function in QM.


Messages In This Thread
Weighted Random Choice - by sirpipthegreat - 09-04-2018, 01:28 AM
RE: Weighted Random Choice - by Start_Learning - 09-05-2018, 07:50 PM
RE: Weighted Random Choice - by sirpipthegreat - 09-05-2018, 09:05 PM
RE: Weighted Random Choice - by Kevin - 09-06-2018, 02:26 AM
RE: Weighted Random Choice - by AlexZ - 09-06-2018, 03:25 AM
RE: Weighted Random Choice - by Kevin - 09-06-2018, 06:42 AM
RE: Weighted Random Choice - by sirpipthegreat - 09-06-2018, 01:02 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)