Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A data structure for non-deterministic element selection in C++11

License

NotificationsYou must be signed in to change notification settings

Dakostu/GrabBag.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GrabBag is a data structure for non-deterministic element selection in C++11.

By using templates and the C++ STL, this class aims to be as versatile of a data structure as possible.

The GrabBag concept in a nutshell

Insert an element into a GrabBag, grab a random element out of the GrabBag.

How to Use

GrabBag is defined in a single header file, a simple include directive will suffice.

For a more in-depth explanation, check out the "documentation" folder which includes a thorough class explanation with code examples.

Simple Usage Example

A most simple use case for a GrabBag would be simulating a lottery game.

The following example shows the usage of GrabBag inside such a lottery program.

#include"src/GrabBag.h"#include<iostream>#include<set>// Select 6 numbers out of 49intmain() {        GrabBag<int> enaLottoPool;    std::set<int> pickedNumbers;for (int i =1; i <=49; ++i)        enaLottoPool += i;for (int j =0; j <6; ++j)        pickedNumbers.insert(enaLottoPool.grab());// Output Picked Numbers    std::cout <<"Picked Numbers:";for (int number : pickedNumbers)        std::cout << number <<"";    std::cout << std::endl;    }

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp