Skip to content

Commit

Permalink
Add random(), randbits(), uniform()
Browse files Browse the repository at this point in the history
  • Loading branch information
fxrlxrn committed Jun 3, 2023
1 parent 4f36908 commit b7df7e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pystd/random.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Sequence

_seed = 0
_seed = 4


def seed(a: int = None, version: int = 2):
Expand All @@ -17,19 +17,21 @@ def setstate(state: object):


def getrandbits(k) -> int:
...
return randint(0, 2**k - 1)


def randbytes(n: int) -> bytes:
...


def random() -> float:
...
return randint(0, 10**8 - 1) / 10**8


def uniform(a: float, b: float) -> float:
...
if a > b:
a, b = b, a
return a + (b - a) * random()


def randint(a: int, b: int) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_randbits_len():
bits = random.getrandbits(i)
assert type(bits) is int
assert bits >= 0
assert bits.bit_count() <= i
assert bits.bit_length() <= i


def test_randint():
Expand Down

0 comments on commit b7df7e7

Please sign in to comment.