Skip to content

msavitskiy/rwep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rwep

randomized weighted elements provider

Usage

...
        // setup source
        Map<String, Double> source = new HashMap<>();
        source.put("key", 100D);
        source.put("yek", 1D);
        
        // create producer
        Producer<String> producer = new Producer<>(source);
        
        // pick one random element
        String key = producer.produce();
        assert key.equals("key");
        
        // pick two random elements
        Collection<String> collection = producer.produce(2);
        assert collection.contains("key") && collection.size() == 2 && !collection.contains("yek");
        
        // pick two random unique elements
        Collection<String> unicCollection = producer.produce(2, true);
        assert unicCollection.contains("key") && unicCollection.contains("yek");
        
        
        // stateless style
        assert "key".equals(Producer.produce(source));
...

About

randomized weighted elements provider

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages