From 82e41d92ce2483da05243dccfa2d5c932e462054 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 15 Sep 2020 08:12:02 +0200 Subject: [PATCH] new style for numpy random numbers https://numpy.org/doc/stable/reference/random/index.html?highlight=random#quick-start https://albertcthomas.github.io/good-practices-random-number-generators/ --- python/damask/_rotation.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index ac7b3ace8..a2f3cba69 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -613,13 +613,29 @@ class Rotation: return Rotation.from_quaternion(np.real(vec.T[eig.argmax()]),accept_homomorph = True) @staticmethod - def from_random(shape=None): + def from_random(shape=None,seed=None): + """ + Draw random rotation. + + Rotations are uniformly distributed. + + Parameters + ---------- + shape : tuple of ints, optional + Shape of the sample. Defaults to None which gives a + single rotation + seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional + A seed to initialize the BitGenerator. Defaults to None. + If None, then fresh, unpredictable entropy will be pulled from the OS. + + """ + rng = np.random.default_rng(seed) if shape is None: - r = np.random.random(3) + r = rng.random(3) elif hasattr(shape, '__iter__'): - r = np.random.random(tuple(shape)+(3,)) + r = rng.random(tuple(shape)+(3,)) else: - r = np.random.rand(shape,3) + r = rng.random((shape,3)) A = np.sqrt(r[...,2]) B = np.sqrt(1.0-r[...,2])