DEV Community

Amohammadi2
Amohammadi2

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

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

Discussion (12)

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

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.

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

Guys, this betsofa.com/ 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.

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

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 betpokies.com/crypto-casinos , 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!

Collapse
markkenzi profile image
Info Comment hidden by post author - thread only accessible via permalink
MarkKenzi

Hello. Friends, I love gambling and its design. Here at syndicate online casino reviews, you have found cool information and lists of online casinos that give many bonuses when registering. I advise you to read reviews about the casino and choose a site for yourself.

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

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.

Collapse
jamestench profile image
JamesTench

top, thx

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

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