Skip to main content

〰️ HalfRand

Small, reproducible pseudo-random sequences with smooth, bounded changes.

CI Python 3.10+ License: MIT

HalfRand is a lightweight Python library for producing random-walk-like data. The first value is sampled randomly (or supplied by you), then each following value changes by no more than a configurable step. It is useful for demos, mock time series, simulations, animations, and tests that need natural-looking variation.

[!NOTE] HalfRand produces pseudo-random data and is not suitable for cryptography, security, gambling, or scientific sampling that requires independent observations.

✨ Features

  • Dependency-free library core built on the Python standard library
  • Reproducible results with local, isolated seeded generators
  • One-shot, stateful, and infinite-iterator APIs
  • Optional lower and upper bounds
  • CSV command-line interface
  • Type hints, tests, packaging metadata, and CI

📦 Installation

Install the latest release when it is available on PyPI:

python -m pip install halfrand

Or install the current GitHub version:

python -m pip install "git+https://github.com/KageRyo/HalfRand.git"

For local development, see CONTRIBUTING.md.

🚀 Quick start

Convenience API

from halfrand import generate

values = generate(8, seed=42, step=0.05)
print(values)

The same seed and arguments produce the same values:

assert generate(8, seed=42) == generate(8, seed=42)

Bounds and starting value

temperatures = generate(
    24,
    seed=7,
    start=20.0,
    step=0.8,
    lower=15.0,
    upper=30.0,
)

Bounds use clipping: a step that crosses a boundary lands exactly on that boundary.

Stateful and streaming APIs

from itertools import islice
from halfrand import HalfRandom

generator = HalfRandom(seed=42, step=0.1)
first_batch = generator.generate(5)
second_batch = generator.generate(5)  # continues consuming the generator's random state

stream = HalfRandom(seed=42).iter(start=0.5)
first_ten = list(islice(stream, 10))

🖥️ Command line

Installing the package provides a halfrand command. It writes CSV to standard output:

halfrand 5 --seed 42

Write a larger bounded sequence to a file:

halfrand 100 --seed 42 --step 0.05 --lower 0 --upper 1 --output values.csv

Run halfrand --help for all options. The legacy python main.py entry point remains available and delegates to the same CLI.

🧠 How it works

Given the current value x and maximum step s, HalfRand samples d uniformly from [-s, s] and computes the next value as x + d. Configured bounds then clip the value:

x₀ = supplied start, or Uniform(lower, upper)
xₙ = clip(xₙ₋₁ + Uniform(-step, step), lower, upper)

Adjacent values are correlated. The word “half” describes this balance between random movement and continuity; it is not a formal statistical term.

📚 API reference

generate(count, *, step=0.1, seed=None, start=None, lower=None, upper=None)

Returns a list[float]. count must be a non-negative integer, step must be non-negative, and lower cannot exceed upper. An empty count returns an empty list.

HalfRandom(step=0.1, seed=None, lower=None, upper=None)

A reusable generator with generate(count, *, start=None) and iter(*, start=None) methods. Each instance owns its random state and does not modify random's global state.

Compatibility

The original randomNum(n) function is temporarily available but deprecated. New code should use generate(n).

🤝 Community and support

🏷️ Versioning and releases

HalfRand follows Semantic Versioning. The initial library release is 0.1.0: its public API is usable, but the 0.x series leaves room to refine that API before committing to 1.0.0 compatibility guarantees. Maintainers can follow the release checklist; pushing a matching v* tag triggers the automated PyPI and GitHub release workflow.

📄 License

HalfRand is available under the MIT License.

Made with ❤️ for the open-source community.

Download files

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

Source Distribution

halfrand-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

halfrand-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file halfrand-0.1.0.tar.gz.

File metadata

  • Download URL: halfrand-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for halfrand-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c3507fdc30aef1a88d8ca615a54a897e1aea33ce37d7736cd4222ead6baf9fb
MD5 f4f291a1d84ef3accec3b97961e427f9
BLAKE2b-256 a7792fefdde324ceb27331dd54a08e843341e0a4597d119c6750d68aa6ceb5de

See more details on using hashes here.

Provenance

The following attestation bundles were made for halfrand-0.1.0.tar.gz:

Publisher: release.yml on KageRyo/HalfRand

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file halfrand-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: halfrand-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for halfrand-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc2f2eaa9565dabf1f8a8bc6d0d3662e3c9786a7e5316e1414bffa0589076b3d
MD5 d4f63939d652a781c64427d4fafa7a4d
BLAKE2b-256 340b928fbd8a93f2dfb8ed2375502fb081d9242ecf181437bda2d058aa2fb6f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for halfrand-0.1.0-py3-none-any.whl:

Publisher: release.yml on KageRyo/HalfRand

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

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