Skip to main content

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

Metadata

Release files for lib-pcg-algopy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lib-pcg-algopy 1.0.0
File Size Uploaded Provenance Actions
lib_pcg_algopy-1.0.0.tar.gz 5.6 kB Without provenance Details for lib_pcg_algopy-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lib-pcg-algopy 1.0.0
File Interpreter ABI Platform Actions
lib_pcg_algopy-1.0.0-py3-none-any.whl Python 3 none any Details for lib_pcg_algopy-1.0.0-py3-none-any.whl

Total release size: 13.7 kB

Release files / lib_pcg_algopy-1.0.0.tar.gz

Download URL lib_pcg_algopy-1.0.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
81fade26b71e2a5466f223636acc75299ecb2b3413b56deb5c04ec24ddf0addc
BLAKE2b-256 checksum
How to use checksums
31c2fbe0f79aa7355233a600887020009de54601e294ead2062b7d0210948f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

Release files / lib_pcg_algopy-1.0.0-py3-none-any.whl

Download URL lib_pcg_algopy-1.0.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d6749581a62d7773d87e6dc8ef132531e584d0272c20bb254fbe86946475b96
BLAKE2b-256 checksum
How to use checksums
537d03e1d88dc409bc1e8d56e496ba834fbdfeabdfb3bb05ce3ed87125d86401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure

Security for lib-pcg-algopy 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page