From 50bcfe6e0da5c982893be47df6764c16400180b0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 26 Jun 2015 06:32:25 +0000 Subject: [PATCH] possibility to give fixed seed to random orientation --- lib/damask/orientation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/damask/orientation.py b/lib/damask/orientation.py index 2afae6b74..1c4696ba0 100644 --- a/lib/damask/orientation.py +++ b/lib/damask/orientation.py @@ -4,7 +4,7 @@ # NOTE: everything here needs to be a np array # ################################################### -import math,random +import math,random,os import numpy as np # ****************************************************************************************** @@ -369,7 +369,10 @@ class Quaternion: @classmethod - def fromRandom(cls): + def fromRandom(cls,randomSeed=None): + if randomSeed == None: + randomSeed = int(os.urandom(4).encode('hex'), 16) + random.seed(randomSeed) r1 = random.random() r2 = random.random() r3 = random.random() @@ -750,11 +753,14 @@ class Orientation: angleAxis = None, matrix = None, Eulers = None, - random = False, + random = False, # put any integer to have a fixed seed or True for real random symmetry = None, ): if random: # produce random orientation - self.quaternion = Quaternion.fromRandom() + if isinstance(random, bool ): + self.quaternion = Quaternion.fromRandom() + else: + self.quaternion = Quaternion.fromRandom(randomSeed=random) elif isinstance(Eulers, np.ndarray) and Eulers.shape == (3,): # based on given Euler angles self.quaternion = Quaternion.fromEulers(Eulers,'bunge') elif isinstance(matrix, np.ndarray) : # based on given rotation matrix