Select value from arraylist based on its percentage [duplicate]
问题 This question already has answers here : How to pick an item by its probability? (12 answers) Closed 4 years ago . I got an arraylist of objects. Each objects got 2 values, content and weight . content is just a simple string while weight decides the percentage of how often the string should be used. If I have 2 objects in the array: Object 1: content: hello weight: 20 Object 2: content: hey weight: 80 First objects content should be used 20% of times while the second objects content should