Skip to main content

A high-entropy random number generation library

Project description

Python PyPI GitHub

The English version of the README.md file was created by a translator. Therefore, the translation may not be accurate. If you can use Korean, we recommend that you view the Korean document. 한국어 문서 바로가기(korean)

Ranpick

PyPI - Version PyPI - Python Version PyPI Downloads PyPI Downloads

Ranpick complements the shortcomings of the existing PRNG method and generates random numbers with nanoseconds and hash-based systems.


Installation

  1. Use 'pip' to install the ranpick:

    pip install ranpick
    
  2. Add the import statement below to the code (.py) to import the ranpick:

    from ranpick import (modules)
    

Modules and Use Guides

As of 2024.12.22 (KST), the modules currently available are as follows.

  • rannumber: Produces a random number in the form of a number
  • ranrandom: Select a random value from the list. (2.1.0~)

number - Generating a numeric random number

Number generates a random number in the form of a normal number.

You can generate numbers up to 01(3.0.0).

The basics

The number module can be used in the following ways.

random_number = rannumber()  # random_number variable, store the random number (~100000000) that is selected as the random number module.

print(random_number) # print_number The value of the variable random_number.
print(rannumber()) #rampicknumber Outputs the value of the random number drawn by the module.

This is the basic method of using the number module. You can generate random numbers with rannumber().

Limiting the Number of Random Numbers

You can also limit the number of random numbers. The example code below limits random numbers to between 5 and 10.

limit_number = rannumber(5, 10)

print(limit_number)
print(rannumber(5, 10))

number(5, 10) is a code that limits the number of random numbers to between 5 and 10. You can complete it by adding starting numbers, arriving numbers in ().

Calculations such as ' 2+3,10/2 can also be used to limit the number of random numbers and can be used in all the contents to be described later.

Set decimal place

By default, a generated random number can only be generated with integers. However, if you refer to the example below, you can output a small number of outputs.

decimal_number = rannumber(0, 1, "d3")

print(decimal_number)
print(rannumber(0,1, "d3"))

This example code is a code that outputs numbers between 0 and 1 up to three decimal places. "d3" means that it outputs up to three decimal places.

If "d4" is used, it can be output up to four decimal places.

It can be up to 20 digits.(3.0.0~)

Application

The codes below are created by applying this module, other libraries, and modules. In addition to the examples used here, a variety of other libraries and applications are possible.

DataTime Library Application

Below is the code applied using the datetime library.

import ranpick
from datetime import datetime

date_number = int(datetime.now().strftime("%Y%m%d%H%M%S"))

print(rannumber(date_number, date_number × 10))

This code was made to output random numbers by leveraging the time output from the datetime library.

ranrandom - Random Value Selection

ranrandom selects and outputs a random value from a list.

Basic Usage

You can use the ranrandom module as shown below:

random = ranrandom("left", "right", "center", "miss")

print(random)
print(ranrandom("left", "right", "center", "miss"))

You can use ranrandom(). Inside the parentheses, you can input items in a format such as ("win", "miss"). One of the items listed here will be randomly selected. At least two items must be provided.

Setting Probabilities

You can set the probabilities for each item. Please refer to the example code below:

random = ranrandom(("left", 33), ("right", 33), ("center", 33), ("miss", 1))

print(random)
print(ranrandom(("left", 33), ("right", 33), ("center", 33), ("miss", 1)))

You can add another pair of parentheses () inside the main (). Within this added (), you can specify items in the format ("item_name", probability[%]). The total sum of all probabilities must equal 100, otherwise an error will occur.

print(ranrandom("left", ("right", 50), "center", "miss"))

If some probabilities are omitted as shown above, the remaining probabilities will be automatically redistributed among the unspecified items.

Multiple selection (2.2.0~)

Of course, multiple selection is possible. Please follow the example below.

random = ranrandom("a", "b", "c", "d", DS=2)

print(random)

This code selects 2 out of a, b, c, d and prints them. DS is in charge of how many to select and print.

If the value of DS is 2, 2 are selected from the list. If DS=3, 3 are selected and printed.

a, d

It is printed like this.

Print in list form

Duplicated values ​​can also be printed in list form.

random = ranrandom("a", "b", "c", "d", DS=3, as_list=True)

print(random)

If you want to print in list format, use as_list. If you set the value of as_list to True and run it, it will print as follows.

['b', 'c', 'a']

Bug report

Please report bugs on the site below (github).

https://github.com/yhg4908/ranpick.py/issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ranpick-3.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ranpick-3.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file ranpick-3.0.0.tar.gz.

File metadata

  • Download URL: ranpick-3.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for ranpick-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9955e8c28274f9ba3f614bffb036062d8d74a32222fb47194be8ca9b10360f6f
MD5 fddc911890126a2affb4323a1dd88c9e
BLAKE2b-256 c1844dc02e5767372b076543983ff1391e30c038782f3e840f9a44798abbe32f

See more details on using hashes here.

File details

Details for the file ranpick-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: ranpick-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for ranpick-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78d70ee4fc4025dfb63c4e6d14440d67130c75646f4c5b9c16a8723b6965ed66
MD5 3f5bd261ac493c3e20743b8d0179d63b
BLAKE2b-256 f6c7285fa7402c2408dc8bac070f3f646bcdd66541d1a274fe540399690aa291

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page