GithubHelp home page GithubHelp logo

sidharthmudgil / py-mrandom Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 14 KB

Python package to generate random numbers

Home Page: https://pypi.org/project/py-mrandom/

License: MIT License

Python 100.00%
mersenne-twister python python-package random random-number-generator

py-mrandom's Introduction

mrandom

This package provides a random number generator. It is based on the Mersenne Twister algorithm. It includes both 32 and 64 bit versions of the algorithm. The generator has large period of 2^19937-1

Features

  • Can generate random numbers
  • Can return a choice from a list
  • Can shuffle a list
  • Can flip a coin
  • Can roll a die
  • Can shuffle a deck

Installing the package

pip install mrandom

Importing the module

>>> import mrandom

# 1 = 32 bit, 2 = 64 bit algorithm
>>> random = mrandom.RandomGenerator(s)

Examples

Return a random number between 0 and 1

>>> print(random.rand())
0.9888888888888889

Return a random number between a and b (inclusive)

>>> print(random.randint(a, b))
1

Return a random number between a and b (exclusive)

>>> print(random.randrange(a, b))
12

Return k random numbers between a and b (inclusive)

>>> print(random.sample(a, b, k))
[1, 2, 3, 4, 5]

Return a random number from a list l

>>> print(random.choice(l))
21

Return shuffled list l

>>> print(random.shuffle(l))
[1, 3, 5, 4, 2]

Return sample of flipping k coins n times

>>> print(random.flip_coin(n, k))
[1, 0, 0, 1, 0]

Return sample of rolling k dices n times

>>> print(random.roll_dice(n, k))
[[1, 4], [1, 1]]

Return sample of picking a card from a deck of 52 cards n times

>>> print(random.shuffle_deck(n))
["Ace of Spades", "Ace of Hearts", "Ace of Clubs", "Ace of Diamonds", "Ace of Clubs"]

Classes mrandom.RandomGenerator - Random number generator

Methods

Methods Description
rand() Return a random number between 0 and 1
randint(a, b) Return a random number between a and b (inclusive)
randrange(a, b) Return a random number between a and b (exclusive)
sample(a, b, k) Return k random numbers between a and b (inclusive)
choice(l) Return a random number from a list l
shuffle(l) Return shuffled list l
flip_coin(n, k) Return sample of flipping k coins n times
roll_dice(n, k) Return sample of rolling k dices n times
shuffle_deck(n) Return sample of picking a card from a deck of 52 cards n times

py-mrandom's People

Contributors

sidharthmudgil avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.