Skip to main content

PCG library implemented using Algorand Python

Project description

PCG Random Number Generator, AVM Edition

lib-pcg-algopy

This AlgoKit subproject implements PCG in Algorand Python. For more general info on this library, see the main page.

Getting Started

Install lib-pcg-algopy in your project. Using poetry, this looks like:

poetry add lib-pcg-algopy

The typical use case of using the library to generate a sequence of pseudo-random numbers looks like:

from algopy import arc4
from lib_pcg import pcg32_init, pcg32_random

class YourContract(arc4.ARC4Contract):
  @arc4.abimethod
  def your_method(self, ...) -> ...:
    # Here you would acquire a safe randomness seed.
    ...
    
    # Seed the PRNG
    state = pcg32_init(<your_randomness_seed>)
  
    # Generate a sequence
    state, sequence = pcg32_random(state, <lower_bound>, <upper_bound>, <sequence_length>)
  
    # The rest of your program
    ...

You can also take a look at the exposer contracts: [ 1, 2, 3 ]

Usage

All generators all use pcg<N>_init() for seeding the algorithm.

To generate a sequence, use pcg<N>_random().

You can pass non-zero lower_bound and upper_bound arguments to pcg<N>_random() to get integers in a desired range.
Note that:

  • lower_bound is always included in your range.
  • upper_bound is always excluded by your range.
  • You can set them independently.
  • The range should be at least two elements wide.

When either bound is set to zero, that bound is not applied.

Feature Support

  • Package published on PyPI
  • 8 / 16 / 32-bit generator
  • 64-bit generator
  • 128-bit generator

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

lib_pcg_algopy-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

lib_pcg_algopy-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file lib_pcg_algopy-1.0.0.tar.gz.

File metadata

  • Download URL: lib_pcg_algopy-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for lib_pcg_algopy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 81fade26b71e2a5466f223636acc75299ecb2b3413b56deb5c04ec24ddf0addc
MD5 be592629d0c3a87aa385e2eec799bea2
BLAKE2b-256 31c2fbe0f79aa7355233a600887020009de54601e294ead2062b7d0210948f92

See more details on using hashes here.

File details

Details for the file lib_pcg_algopy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lib_pcg_algopy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for lib_pcg_algopy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6749581a62d7773d87e6dc8ef132531e584d0272c20bb254fbe86946475b96
MD5 3671684feddab4e9f6375c23a6d2f16b
BLAKE2b-256 537d03e1d88dc409bc1e8d56e496ba834fbdfeabdfb3bb05ce3ed87125d86401

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