Random for modern C++ with convenient API

Random for modern C++ with convenient API
0.0 0

#1

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:


#2

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)


#3

Yes, it is!

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


#4

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


#5

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.


#6

Just to make cocos better :slight_smile:


#7

cocos already have the required random functions


#8

Cool, thanks for sharing