Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit 836c921

Browse files
authoredFeb 18, 2023
Add get_seed() and test/doc (#40)
1 parent bfbdc06 commit 836c921

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
 

‎README.md

+8
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ For more advanced examples, see the files in the [tests](./tests/) and [examples
9797

9898
random_seed()
9999

100+
**get_seed()**
101+
102+
Return the value used to seed the initial state.
103+
:return: seed as integer
104+
105+
>>> get_seed()
106+
3
107+
100108
**opensimplex.noise2(x, y)**
101109

102110
Generate 2D OpenSimplex noise from X,Y coordinates.

‎opensimplex/api.py

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def random_seed() -> None:
3333
seed(time.time_ns())
3434

3535

36+
def get_seed() -> int:
37+
"""
38+
Return the value used to seed the initial state.
39+
:return: seed as integer
40+
41+
>>> get_seed()
42+
3
43+
"""
44+
return _default.get_seed()
45+
3646
def noise2(x: float, y: float) -> float:
3747
"""
3848
Generate 2D OpenSimplex noise from X,Y coordinates.
@@ -143,6 +153,10 @@ def noise4array(x: np.ndarray, y: np.ndarray, z: np.ndarray, w: np.ndarray) -> n
143153
class OpenSimplex(object):
144154
def __init__(self, seed: int) -> None:
145155
self._perm, self._perm_grad_index3 = _init(seed)
156+
self._seed = seed
157+
158+
def get_seed(self) -> int:
159+
return self._seed
146160

147161
def noise2(self, x: float, y: float) -> float:
148162
return _noise2(x, y, self._perm)

‎tests/test_opensimplex.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def test_seeds(self):
2626
if n != row[1]:
2727
self.fail("got %s, expected %s (using seed %s)" % (n, row[1], row[0]))
2828

29+
got = simplex.get_seed()
30+
want = test_seeds[-1][0]
31+
if got != want:
32+
self.fail("got %s, expected %s" % (got, want))
33+
2934
def load_samples(self):
3035
for line in gzip.open("tests/samples.json.gz"):
3136
# Python3: need to decode the line as it's a bytes object and json
@@ -53,7 +58,7 @@ def test_samples(self):
5358
expected = s[4]
5459
actual = simplex.noise4(s[0], s[1], s[2], s[3])
5560
else:
56-
self.fail("Unexpected sample size: " + str(len(s)))
61+
self.fail("unexpected sample size: " + str(len(s)))
5762
self.assertEqual(expected, actual)
5863

5964
def test_arrays(self):

0 commit comments

Comments
 (0)
This repository has been archived.