Random for modern C++ with convenient API

Behold, the newest C++ library which can make game development easier.

Many games, including the one I develop with cocos2d-x often works with randomness. Therefore, at the beginning of my projects I developed a library that greatly simplifies working with randomness in C++.

The time has come - all the power of the randomness is hidden in one header file.

90% of the randomness can be controlled through ONE get method

Examples:

  1. Get random number in range

auto val = Random::get(-1, 1); // Integer
auto val = Random::get(1.f, -1.f); // Float point

  1. Get bool with [0; 1] probability

if( Random::get( .5) ) // 50% probability of true
{
…
}

  1. Random value from std::initilizer_list

// Set random color from init_list
setColor( Random::get( {
Color3B::MAGENTA, Color3B::YELLOW,
Color3B::ORANGE, Color3B::RED } ) );

  1. Random iterator from container

auto randomSprite = Random::get( sprites );

And even more! Check out github page:

1 Like

I’m just using this http://www.cocos2d-x.org/reference/native-cpp/V3.3rc0/dc/d01/classcocos2d_1_1_random_helper.html is it worse? Honestly, I never checked it’s code)

Yes, it is!

With my library you can do more things in the SIMPLEST way.

Probably you can push it as pull request to new class in cocos2d-x?

It is needed? My ‘random’ library depends only on C++11. You can just include the single file “random.hpp” or with subdirectory “effolkronium/random.hpp” into your “Classes” folder.

Just to make cocos better :slight_smile:

cocos already have the required random functions

Cool, thanks for sharing