I have to make a List of let's say 10 items of different types.
For example:
- item A. probability 90%
- item B. probability 90%
- item C. probability 90%
- item D. probability 30%
- item E. probability 20%
- item F. probability 10%
- item G. probability 1%
How could I get this list?
I've tried an approach showed by the first and for the third down (based on upvote) answers under this question: How to pick an item by its probability?
But as far as I understood all of these need a code line for every possible element, for example, if(Random.nextDouble(1) <= item.probability){List.add(item)}
and while mathematically correct, this approach would request new logic for every item and wouldn't be easy to adjust to new items and wouldn't fit well with items that have the same probability of appearing.
I cannot quite understand The Second Question (The Accepted One), but as far as I've understood it also uses a per-item way of doing it (I Might be wrong, sorry, it's very condensed and it's java).
So I was looking for something more like this: A weighted version of random.choice The answer I linked is in python, and is a single line implementation of the method numpy.choice which could then be put into a cicle from 0 to X to run X times. Is there a way of doing something like this in Dart?