DEV Community


Posted on

Casino_plus, an easy way to create uniform and non-uniform random distributions

Casino_plus is a C++ library for creating both uniform and non-uniform random distributions. The good thing about this library is, it has python language bindings as well, so you can use it in your python projects as well.

This library has a very easy to use interface for python programmers, also it is really fast.

In this article, I want to show you how to use python bindings of this library. So let's begin


the installation process is fairly simple. here is the requirements:

  • Visual C++ build tools 2017 or higher
  • CMake version 3.8 or higher

here is the github repo:

GitHub logo Amohammadi2 / Casino_plus

create uniform and non-uniform distribution

first go ahead and clone the repository:

$ git clone
Enter fullscreen mode Exit fullscreen mode

Then, cd into the project root directory, there you can find a file. (installation verified on python version 3.8)

$ python install
Enter fullscreen mode Exit fullscreen mode

If you have the required tools installed, the installation will finish successfully.

How to use it

you have to import the module before you can use it, write the following code in a python file:

import CasinoPlus
Enter fullscreen mode Exit fullscreen mode

the module contains a class called CasinoRandomGenerator but due to constraints of C++ type system, there are some prefixes that you should use based on the data type you want to pass to the generator.

  • s_ : for generators containing strings
  • cs_ : for generators containing chars
  • i_ : for generators containing ints
  • f_ : for generators containing floats
  • d_ : for generators containing doubles

for example you could use: s_CasinoRandomGenerator to create a generator that accepts string items

at the time being, only the types mentioned above are supported. We'll try to improve it and make it more general.

adding items to the generator

to add items to the generator, you should use one of the methods add_item or add_sequence.

  • add_item(item: Item_Type, probability: int) -> None : adds one item to generator with specified probability. for uniform distributions probability could be set to 1 for all the items but if you want to create non-uniform random distributions, you can change this value. For example if you want the item to appear more frequently, you can increase the probability. probability cannot be a negative value.
  • add_sequence(items: List[Tuple[Item_Type, int]]) -> None : can add multiple items at once. it is more optimal to use this function when you want to add multiple items to the generator.

notice that Item_Type is actually the data type that the generator is using for example if you're using s_CasinoRandomGenerator then Item_Type would be str.

getting a random item out of generator

in order to get a random item, you should use get_random_item method. It has the following signature:

get_random_item() -> Item_Type
Enter fullscreen mode Exit fullscreen mode


here is a example program that uses all the functionalities of CasinoPlus.

>>> from CasinoPlus import s_CasinoRandomGenerator as strgen
>>> rand = strgen()
>>> rand.add_item("Ashkan Mohammadi", 1)
>>> my_brothers = [["Arshia Mohammadi", 1], ["Ilia Mohammadi", 1]]
>>> rand.add_sequence(my_brothers)
>>> rand.get_random_item()
'Ilia Mohammadi'
>>> rand.get_random_item()
'Ashkan Mohammadi'
>>> rand.get_random_item()
'Arshia Mohammadi'
Enter fullscreen mode Exit fullscreen mode

Top comments (17)

johnram98468527 profile image
Info Comment hidden by post author - thread only accessible via permalink

Hello, to all those who like to play in a free minute. I stalled my choice at online casinos, and I think that many will support me in this. Because if you approach the game wisely, you can still make good money on this. If you are also interested in this topic, I advise you to read about big time gaming online casinos. This is often the most productive way to get acquainted with gambling platforms.

almasmiths profile image
Info Comment hidden by post author - thread only accessible via permalink

You have a well-written post. This code helps my business. I am working a casino club, So i have need this type code. if you want to check my club ad club offer, So you have a peek at these guys. I hope so, You will focus on this.

jo4350 profile image
Info Comment hidden by post author - thread only accessible via permalink

Guys, this is a normal casino! The minimum deposit is only $10, and you can scroll for a week. And there cashback will get. All my friends are here, so I also decided to keep up with my friends. None of us have become a millionaire yet, but it's not over yet! Some of us dream of collecting an apartment or a car in this way. I understand that this is unrealistic, but if you like it, then let yourself. After all, a game is needed for thrill. And the efficiency and functionality of this site allow you to enjoy such moments to your heart's content.

bobdevil64 profile image
Info Comment hidden by post author - thread only accessible via permalink

Recently, I have started to get involved in various gambling games. I also like to invest in cryptocurrency. So when I found a good one it's bitcoin casino australia , I was very happy about it. Since this allowed me to withdraw my winnings into cryptocurrency without any problems and invest it in the stock market! It's very useful and cool!

jamestench profile image

top, thx

arminkhans profile image
Info Comment hidden by post author - thread only accessible via permalink

I like betting on badminton because you can predict the exact score of the match. Again, few variations are possible - 2-0, 2-1, 1-2, 0-2. In our game, a 2-0 bet will be played. The odds are usually pretty high for such bets, but they are not that difficult to predict. The situation is much more difficult when you need three games to win, but it is not recommended that beginners bet on the exact score in such games. The exact score in a game is also suggested. But as a betting man, I started betting at a long time ago and still do. And I like this stability because I prefer only the tried and tested bookmakers.

kargataz profile image

Ebben az áttekintésben részletesen megvizsgáljuk a által kínált promóciós kódokat és bónuszokat. A platform rendszeresen kínál különböző promóciókat, amelyek növelik a felhasználók játékélményét és esetleges nyerési lehetőségeit. A promóciós kódok lehetőséget kínálnak a felhasználóknak extra bónuszok és előnyök igénylésére. A kódokat általában a regisztráció vagy befizetés során lehet használni, és ezek segítenek fokozni az induló tőkét. Az új felhasználók gyakran részesülnek üdvözlő bónuszokban, amikor regisztrálnak és elindítják a játékukat. Ez lehet extra pénz a befizetésekhez vagy ingyenes fogadások a platform kínálatában. A időszakonként új és izgalmas promóciókat kínál. Ezek lehetnek szezonális ajánlatok, különleges eseményekhez kapcsolódó promóciók vagy akár versenyek, amelyeken való részvétel extra jutalmakat hozhat. A platform gyakran kínál bónuszokat a felhasználóknak, akik bizonyos feltételekkel befizetést hajtanak végre. Ez lehet a befizetett összeg százalékos növekedése vagy extra pénz a számlára.

cevin77 profile image
Info Comment hidden by post author - thread only accessible via permalink

Very interesting article! But you know, I'm quite a gambling person and have been trying to find a good casino for a long time! If someone tells me where to find him, I will be very grateful!

Some comments have been hidden by the post's author - find out more