Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
src/com/oppalove/collection
README.md

README.md

Weighted Random Collection

The weighted random collection is the collection to get the value randomly by weighted value.

Usage

Create Instance

WeightedRandomCollection<String> collection = new WeightedRandomCollection<>();

Add element

collection.add(5, "This is 50%!!!!!");
collection.add(3, "This is 30%!!!");
collection.add(2, "This is 20%!");

Get element

collection.get();

Play

Run

// Since we use a random function, we will get different results each time.
        IntStream.range(1,10)
                .forEach(i-> System.out.println(collection.get()));

Results

This is 30%!!!
This is 50%!!!!!
This is 30%!!!
This is 20%!
This is 30%!!!
This is 50%!!!!!
This is 50%!!!!!
This is 30%!!!
This is 50%!!!!!
You can’t perform that action at this time.