Skip to content

Instantly share code, notes, and snippets.

@belltailjp
Created February 6, 2013 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save belltailjp/4722583 to your computer and use it in GitHub Desktop.
Save belltailjp/4722583 to your computer and use it in GitHub Desktop.
C++11のstd::discrete_distributionを使ったときのおみくじプログラム
#include <iostream>
#include <random>
int main()
{
std::vector<int> prob = {1, 9, 25, 25, 30, 9, 1};
const std::string str[] = {"大吉", "中吉", "小吉", "吉末", "吉", "凶", "大凶"};
std::mt19937 rng;
std::discrete_distribution<int> dst(prob.begin(), prob.end());
//おみくじを引きまくる
while(1)
{
std::cout << str[dst(rng)] << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment