From e2965e78f03fb41c9a02c92ef120caf038b837ae Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 16 Jan 2023 14:34:29 -0500 Subject: use snake case per python coding standard --- lib/utils/prng.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/utils/prng.py') diff --git a/lib/utils/prng.py b/lib/utils/prng.py index 9face2be..33102205 100644 --- a/lib/utils/prng.py +++ b/lib/utils/prng.py @@ -13,7 +13,7 @@ import numpy as np # Using multiple counters for n-dimentional random streams is also possible and is useful for grid-like structures. -def joinArgs(*args): +def join_args(*args): # Stringifies parameters into a slash-separated string for use in hash keys. # Idempotent and associative. return "/".join([str(x) for x in args]) @@ -22,37 +22,37 @@ def joinArgs(*args): MAX_UNIFORM_INT = 2 ** 32 - 1 -def uniformInts(*args): +def uniform_ints(*args): # Single pseudo-random drawing determined by the joined parameters. # To get a longer sequence of random numbers, call this loop with a counter as one of the parameters. # Returns 8 uniformly random uint32. - s = joinArgs(*args) + s = join_args(*args) # blake2s is python's fastest hash algorithm for small inputs and is designed to be usable as a PRNG. h = blake2s(s.encode()).hexdigest() nums = [] for i in range(0, 64, 8): - nums.append(int(h[i:i+8], 16)) + nums.append(int(h[i:i + 8], 16)) return np.array(nums) -def uniformFloats(*args): +def uniform_floats(*args): # Single pseudo-random drawing determined by the joined parameters. # To get a longer sequence of random numbers, call this loop with a counter as one of the parameters. # Returns an array of 8 floats in the range [0,1] - return uniformInts(*args) / MAX_UNIFORM_INT + return uniform_ints(*args) / MAX_UNIFORM_INT -def nUniformFloats(n: int, *args): +def n_uniform_floats(n: int, *args): # returns a fixed number (which may exceed 8) of floats in the range [0,1] - seed = joinArgs(*args) - nBlocks = ceil(n/8) - blocks = [uniformFloats(seed, x) for x in range(nBlocks)] + seed = join_args(*args) + nBlocks = ceil(n / 8) + blocks = [uniform_floats(seed, x) for x in range(nBlocks)] return np.concatenate(blocks)[0:n] -def iterUniformFloats(*args): +def iter_uniform_floats(*args): # returns an infinite sequence of floats in the range [0,1] - seed = joinArgs(*args) - blocks = map(lambda x: list(uniformFloats(seed, x)), count(0)) + seed = join_args(*args) + blocks = map(lambda x: list(uniform_floats(seed, x)), count(0)) return chain.from_iterable(blocks) -- cgit v1.2.3