DEV Community

Amohammadi2
Amohammadi2

Posted on

4 2

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

Installation

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 https://github.com/Amohammadi2/Casino_plus.git
Enter fullscreen mode Exit fullscreen mode

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

$ python setup.py 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

example

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (16)

Collapse
 
bobdevil64 profile image
BobDEvil64
Comment hidden by post author
Collapse
 
jo4350 profile image
Robert
Comment hidden by post author
Collapse
 
mikecook37 profile image
mikecook37

Resort gambling combines luxury and excitement, offering visitors a mixture of relaxation and exciting casino events. These resorts often feature world-class amenities and entertainment, attracting tourists from all over the world. You can also check out 91club if you are interested. Here you can find the same games, only online.

Collapse
 
almasmiths profile image
Almasmiths
Comment hidden by post author
Collapse
 
johnram98468527 profile image
JohnRamsey
Comment hidden by post author
Collapse
 
clublogin profile image
club login

91 Club is an online gaming platform where users can register and log in to enjoy various games and earn rewards.

91 Club Login:

Visit the official 91 Club login page.
Enter your username and password.
Click Login to access your account.
91 Club Register / Registration:

Go to the 91 Club registration page.
Provide the required details (mobile number, OTP, password).
Complete the process and start playing.

Collapse
 
pavel_4c0ba29862ce5d9aaab profile image
Pavel

Si querés acceder a un casino de calidad, solo necesitás iniciar sesión con tu cuenta. Desde cualquier lugar, ingresá tu correo electrónico y contraseña para empezar a jugar. En casino33 casino33-argentina.com/iniciar-ses... la sesión es rápida y segura, con múltiples opciones para todos. No esperes más y descubrí la mejor experiencia en juegos de azar en línea.

Collapse
 
anna_favorskaya_3c7a8cc86 profile image
Anna Favorskaya

Najlepšie Bitcoin kasíno pre slovenských hráčov nájdete v recenziách na špecializovaných stránkach, ktoré hodnotia spoľahlivosť, bezpečnosť, ponuku hier a bonusy jednotlivých kasín. Ak ide o kvalitný a zahraničný zdroj informácií, tak odporúčam stránku s recenziami kasín zahranicneonlinecasino.org/bitcoin.... Táto platforma poskytuje recenzie najlepších Bitcoin kasín pre slovenských hráčov vrátane ich kladov a záporov, takže si môžete vybrať to najlepšie pre svoje potreby. Pomocou tejto stránky nájdete bezpečné možnosti pre svoje hry.

Collapse
 
kargataz profile image
viktorz

Ebben az áttekintésben részletesen megvizsgáljuk a mostbet-hu.com/promocios-kod-bonusz/ á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 Mostbet-hu.com 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.

Collapse
 
arminkhans profile image
Comment hidden by post author

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay