If I have a list such as this
- White British, 85.67
- White (other), 5.27
- White Irish, 1.2
- Mixed race, 1.2
- Indian, 1.8
- Pakistani, 1.3
- Bangladeshi, 0.5
- Other Asian (non-Chinese), 0.4
- Black Caribbean, 1
- Black African, 0.8
- Black (others), 0.2
- Chinese, 0.4
- Other, 0.4
And I want to select 10,000 values from this list for example but I want to have the selected values match the weighting associated with them. So ~85% of the selected values should be 'White British'.
I've been attempting this with LINQ but have had no luck.
var items = from dataItem in listOfItems
where (dataItem.uses / listOfItems.Count) <= dataItem.weighting
select dataItem;
Where uses is how many times that value has been selected and listOfItems.Count is how many have been selected overall so far.
Thanks