Skip to main content

More random utils

Project description

extrarandom

A library that provides extra utilities builtin on the builtin library random.

Installation

pip install extrarandom

Methods

Random booleans

some_bool = randbool()
three_bools = randbools(3)

Random characters

letter = randletter()
uppercase = randuppercase()
lowercase = randlowercase()

Random hex

nine = hex(9)
twenty = hex(20)
sth_between_9_and_20 = randhex(nine, twenty) # returns a string just like hex()

Random string manipulation

mystring = "abcdef"
modified_string = strinsert(mystring, "HELLO")
# some possible outcomes:
# "abHELLOcdef", "HELLOabcdef", "abcdefHELLO", etc

# if you don't want the substring to be inserted at the start/end:
modified_string2 = strinsertin(mystring, "HELLO")
# impossible outcomes:
# "HELLOabcdef", "abcdefHELLO"

Random list manipulation

mylist = [1, 2, 3, 4]
listinsert(mylist, -999)
# some possible outcomes:
# [-999, 1, 2, 3, 4] [1, 2, -999, 3, 4] [1, 2, 3, 4, -999]

# listinsertin is similar to strinsertin

Random permutation/combination

perm = permutation(iterable)
comb = permutation(iterable)

Range objects

some_range_between_6_and_9 = subrange(range(6, 9))
# possible values:
# range(6, 7), range(6, 9), range(8, 9) etc.
# start will not be equal to stop

Random iteration

mylist = [1, 2, 3, 4, 5]
for i in randiter(mylist, total=8):
    print(i)
# print 8 random elements from mylist

Not so useful stuff (yet)

Infinite iterators

for b in randboolstream():
    print(b)
# infinite random boolean stream lol

Random attribute manipulation (not too useful tho)

getrandattr(obj)
setrandattr(obj, value)
delrandattr(obj)

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

extrarandom-1.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

extrarandom-1.0.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file extrarandom-1.0.4.tar.gz.

File metadata

  • Download URL: extrarandom-1.0.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for extrarandom-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a5cebc5e3edb81d2e5f70b29c0b187a50eb3f326a27f4d5172b89a626a36b7e5
MD5 43ec43bc6148d9eb0ea10b20f1a549e8
BLAKE2b-256 f405720bda538202e03016d668241316158c787d4b3cf454d6a1ec6eb13517bc

See more details on using hashes here.

File details

Details for the file extrarandom-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: extrarandom-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for extrarandom-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 01230bee1c6e28fe09a6560d31353b01d3d5a27701d85d9de90f59391f06be77
MD5 bcb0e0d96f182433807112fddfe2a84e
BLAKE2b-256 c9f315d853fa52fc33c2391767bd2f71b9e7c05539dac21d6639e2b94e28821b

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