Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thenithinbalaji committed Mar 19, 2022
1 parent 281ba27 commit 1c0e6da
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PyRandToys
=========
==========

``pyrandtoys`` is a python module containing probability-based toys
functions. It works offline and is compatible with both Python 2 and 3.
Expand Down
8 changes: 8 additions & 0 deletions build/lib/pyrandtoys/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pyrandtoys.functions import dice
from pyrandtoys.functions import coin
from pyrandtoys.functions import dreidel
from pyrandtoys.functions import cat
from pyrandtoys.functions import switch
from pyrandtoys.functions import spinner
from pyrandtoys.functions import combi
from pyrandtoys.functions import card
234 changes: 234 additions & 0 deletions build/lib/pyrandtoys/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import random as rop
from typing import Tuple
from typing import Union


def dice(count: int = 1) -> Tuple[int, ...]:
"""
Rolls N dice
Parameters:
count (int) : The number of dice to roll, default = 1
Returns:
tuple: The result of dice rolls.
Each tuple element is a number between 1 and 6.
"""

res = ()

for _ in range(int(count)):
res += (rop.randint(1, 6),)

return res


def coin(count: int = 1) -> Tuple[str, ...]:
"""
Toss N coins
Parameters:
count (int) : The number of coins to toss, default = 1
Returns:
tuple: The result of coin toss.
A tuple element can be either HEADS or TAILS.
"""

res = ()
sample_space = ["HEADS", "TAILS"]

for _ in range(int(count)):
res += (rop.choice(sample_space),)

return res


def dreidel(count: int = 1) -> Tuple[str, ...]:
"""
Spin a dreidel N times
Parameters:
count (int) : The number times to spin, default = 1
Returns:
tuple: The values of dreidel spins.
Each tuple element is one of these values: NUN, GIMEL, HE, SHIN.
"""

res = ()
sample_space = ["NUN", "GIMEL", "HE", "SHIN"]

for _ in range(int(count)):
res += (rop.choice(sample_space),)

return res


def cat(count: int = 1) -> Tuple[str, ...]:
"""
Perform Schrödinger's cat experiment N times
Parameters:
count (int) : The number of times to perform the experiment, default = 1
Returns:
tuple: The status of cats.
A cat can be either ALIVE or DEAD.
"""
res = ()
sample_space = ["ALIVE", "DEAD"]

for _ in range(int(count)):
res += (rop.choice(sample_space),)

return res


def switch(count: int = 1) -> Tuple[str, ...]:
"""
Toggle a switch N times
Parameters:
count (int) : The number times to toggle a switch, default = 1
Returns:
tuple: The state of switches.
A switch can be either ON or OFF.
"""
res = ()
sample_space = ["ON", "OFF"]

for _ in range(int(count)):
res += (rop.choice(sample_space),)

return res


def spinner(lower: int, upper: int = 0) -> int:
"""
Spin a spinner with numbers from lower to upper value
Parameters:
lower (int) : lowest number on the spinner.
upper (int) : highest number on the spinner.
Returns:
int: The value at which the spinner has stopped spinning.
Result is a number between lower and upper.
"""
if lower > upper:
lower, upper = upper, lower

return rop.randint(int(lower), int(upper))


def card(count: int = 1) -> Tuple[str, ...]:
"""
Picks N cards from a deck of 52 cards
Parameters:
count (int) : The number of cards to pick, default = 1
Returns:
tuple: The cards that have been picked.
Each tuple element is a card from a deck of 52 cards.
"""

SUITS = ("Spades", "Clubs", "Hearts", "Diamonds")
RANKS = (
"Ace",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Jack",
"Queen",
"King",
)

sample_space = [rank + " of " + suit for rank in RANKS for suit in SUITS]

res = ()
for _ in range(int(count)):
res += (rop.choice(sample_space),)

return res


def combi(*argv: Union[str, int, list, tuple]) -> Tuple[Union[int, str], ...]:
"""
Randomise combinations between other functions
Parameters:
Functions to randomise
Returns:
tuple: The values of the randomised functions
"""

res = []

for item in argv:
if isinstance(item, str):
item = item.lower()
try:
res.append(eval(item + "()")[0])
except:
res.append(None)

elif isinstance(item, list) or isinstance(item, tuple):
temp = ()
for i in item:

if isinstance(i, str):
i = i.lower()
try:
temp += (eval(i + "()")[0],)
except:
temp += (None,)

elif isinstance(i, int):
sample_space = ["coin", "dice", "switch", "card"]
temp2 = ()

for _ in range(i):
rand_op = rop.choice(sample_space)
try:
temp2 += (eval(rand_op + "()")[0],)
except:
temp2 += (None,)

temp += (temp2,)

else:
temp += (None,)

res.append(temp)

elif isinstance(item, int):

sample_space = ["coin", "dice", "switch", "card"]
temp = ()

for _ in range(item):
rand_op = rop.choice(sample_space)
try:
temp += (eval(rand_op + "()")[0],)
except:
temp += (None,)

res.append(temp)

res = tuple(res)

if len(res) == 1 and isinstance(res[0], tuple):
return res[0]
else:
return res
Binary file added dist/pyrandtoys-1.0.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/pyrandtoys-1.0.0.tar.gz
Binary file not shown.
127 changes: 127 additions & 0 deletions pyrandtoys.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
Metadata-Version: 2.1
Name: pyrandtoys
Version: 1.0.0
Summary: Python Module for generating the result of probability based toys.
Home-page: https://github.com/thenithinbalaji/pyrandtoys
Author: thenithinbalaji
Author-email: thenithinbalaji@outlook.in
License: UNKNOWN
Keywords: python,random,probability,experiment
Platform: UNKNOWN
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
Classifier: License :: OSI Approved :: MIT License
License-File: LICENSE.md

PyRandToys
==========

``pyrandtoys`` is a python module containing probability-based toys
functions. It works offline and is compatible with both Python 2 and 3.

Installation
~~~~~~~~~~~~

::

pip install pyrandtoys

Usage
~~~~~

::

import pyrandtoys

Dice:
^^^^^

+ **Optional:** Number of Dice ``<int>``
+ **Default:** Number of Dice = 1
+ **Return Type:** ``<tuple>``

::

dice(number_of_dice)

Coin:
^^^^^

+ **Optional:** Number of Coins ``<int>``
+ **Default:** Number of Coins = 1
+ **Return Type:** ``<tuple>``

::

coin(number_of_coins)

Card:
^^^^^

+ **Optional:** Number of Cards ``<int>``
+ **Default:** Number of Cards = 1
+ **Return Type:** ``<tuple>``

::

card(number_of_cards)

Similar Toys:
^^^^^^^^^^^^^

+ **Optional:** Number of Items ``<int>``
+ **Default:** Number of Items = 1
+ **Return Type:** ``<tuple>``

::

dreidel(number_of_dreis)
cat(number_of_cats)
switch(number_of_switches)

Spinner:
^^^^^^^^

+ **Required:** Lower & Upper Limits ``<int>``
+ **Default:** Lower Limit = 0
+ **Return Type:** ``<int>``

::

spinner(lowerLimit, upperLimit)

Toy Combinations:
^^^^^^^^^^^^^^^^^

+ **Default:** Number of Toys = 0
+ **Return Type:** ``<tuple>``

**If you want to use a combination of toys then,**
**Required:** names of toys as ``<tuple>, <list>, <str>``

::

combi("coin", "switch")
combi(("switch", "cat", "dice"))
combi(["dreidel", "coin", "coin", "cat"])

**For combination of x random toys,**

::

combi(x)

Project Links
~~~~~~~~~~~~~

- PyPI
`(https://pypi.org/project/pyrandtoys/) <https://pypi.org/project/pyrandtoys/>`__
- GitHub
`(https://github.com/thenithinbalaji/pyrandtoys) <https://github.com/thenithinbalaji/pyrandtoys>`__


9 changes: 9 additions & 0 deletions pyrandtoys.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LICENSE.md
README.rst
setup.py
pyrandtoys/__init__.py
pyrandtoys/functions.py
pyrandtoys.egg-info/PKG-INFO
pyrandtoys.egg-info/SOURCES.txt
pyrandtoys.egg-info/dependency_links.txt
pyrandtoys.egg-info/top_level.txt
1 change: 1 addition & 0 deletions pyrandtoys.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions pyrandtoys.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyrandtoys

0 comments on commit 1c0e6da

Please sign in to comment.