Skip to main content

Randimizer generates timstamped unique random strings with minimal collision probability.

Project description

GitHub GitHub Workflow Status (with branch) Coverage PyPI - Downloads PyPI

Introduction

This package provides a simple way how to generate timestamped random strings with minimal length of 8 characters. The first 6 characters are the timestamp in seconds and the remaining set of characters (required length - 6) are randomly generated.

The random string is generated using the following set of characters: abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 as you can see the characters l and I are not included to avoid confusion with 1 and 0.

The key advantage of this package is the ability to generate completely unique and not easily predictible strings with the performace:

  • 57 strings per 1 seconds for a length of 7 characters
  • 3,249 strings per 1 seconds for a length of 8 characters
  • 185,193 strings per 1 seconds for a length of 9 characters

Usage

# import the randomizer
from surquest.utils.randomizer import Randomizer

# Generate a timestamped random string with a length of 8 characters
random_string = Randomizer.generate_timestamped_random_string(
    string_length=8
) # returns something like `gechEuKq`

Installation

The package is available on PyPI and can be installed using pip:

pip install surquest-utils-random-string-generator

Additional information

You are also able to submit your own set of characters to be used for the random string generation.

import string
from surquest.utils.randomizer import Randomizer

# Generate a timestamped random string with a length of 8 characters

randomizer = Randomizer(
    string_length=8,
    characters=string.ascii_letters + string.digits
)

random_string = randomizer.generate_timestamped_random_string(10)

The Randomizer class can be also used for conversion of integers to strings based on given set of characters.

from surquest.utils.randomizer import Randomizer

randomizer = Randomizer()

# input number
number = 1234567890

# convert number to string
random_string = randomizer.convert_integer_to_charset(number)

# convert string back to number
number = randomizer.convert_charset_to_integer(random_string)

Local development

You are more than welcome to contribute to this project. To make your start easier we have prepared a docker image with all the necessary tools to run it as interpreter for Pycharm or to run tests.

Build docker image

# powershell syntax (windows)
docker build `
 --tag surquest/utils/randomizer `
 --file package.base.dockerfile `
 --target test .

Run tests

# powershell syntax (windows)
docker run --rm -it `
 -v "${pwd}:/opt/project" `
 -w "/opt/project/test" `
 surquest/utils/randomizer pytest

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

Built Distribution

File details

Details for the file surquest_utils_random_string_generator-0.0.1.tar.gz.

File metadata

File hashes

Hashes for surquest_utils_random_string_generator-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bf2c949c6a1f2c4eafcd2c4a983f0e4847c47f65732a6bb84cd07df62a3e30eb
MD5 a39e36ea58869a080f368198eb21ca2a
BLAKE2b-256 72fb4b7ec13222651ed9faa3b529f47b72a87227dd2fa6fd528933d4b4a1e564

See more details on using hashes here.

File details

Details for the file surquest_utils_random_string_generator-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for surquest_utils_random_string_generator-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7634bd1f13d6063bcc51dbf6ac47b9ccce259a30ba47d2672acdbf43952c675b
MD5 16ed234b1abc90e4e4cbd91231d6bb33
BLAKE2b-256 099f188665de2cce76794b748fb9631559a38b8460595707788ea2c6233224eb

See more details on using hashes here.

Supported by

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